【问题标题】:wpf button with foreground and background as image具有前景和背景作为图像的 wpf 按钮
【发布时间】:2011-05-05 16:50:54
【问题描述】:

在我的 wpf 应用程序中,我有一个按钮。我希望按钮像背景一样有图像,前景也有图像。如何做到这一点?

提前致谢, 卡恩

【问题讨论】:

    标签: wpf


    【解决方案1】:

    我不确定我是否明白你想要什么,但这里有两个例子

    前景和背景两个不同的图像

    <Button Content="Button" FontSize="50" Margin="0,0,263,155">
        <Button.Background>
            <ImageBrush ImageSource="C:\Time.png"/>
        </Button.Background>
        <Button.Foreground>
            <ImageBrush ImageSource="C:\C1.png"/>
        </Button.Foreground>
    </Button>
    

    与前景和背景相同的图像

    <Button Content="Button"
            FontSize="50"
            Foreground="{Binding RelativeSource={RelativeSource self}, Path=Background}">
        <Button.Background>
            <ImageBrush ImageSource="C:\Time.png"/>
        </Button.Background>
    </Button>
    

    【讨论】:

    • +1 我忘了ImageBrush!这可能就是 OP 的全部需求。
    【解决方案2】:

    通常,您需要使用Style 和/或ControlTemplate 覆盖按钮的默认外观。

    例如,您可能想查看:

    如果您遇到问题,请随时提供更多细节或一些代码,我们将能够提供进一步的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 2016-07-12
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多