【问题标题】:How can I set the Content of a WPF Button to have multiple colors?如何将 WPF 按钮的内容设置为具有多种颜色?
【发布时间】:2015-06-27 16:00:44
【问题描述】:

我希望我的 WPF ButtonContent 使用多种颜色,例如:

<Button Name="MyButton">
    <Blue>This is</Blue
    <Red>Red</Red>
</Button>

我发现我不能像在TextBlock 中那样使用多个Runs - 实现此效果的正确方法是什么?

【问题讨论】:

    标签: wpf xaml button colors wpf-controls


    【解决方案1】:

    您可以将TextBlock 用作Button.Content

    <Button Name="MyButton">
        <TextBlock>
            <Run Foreground="Blue" Text="This is Blue"/>
            <Run Foreground="Red" Text=" This is Red"/>
        </TextBlock>
    </Button>
    

    ButtonContentControl 并因此

    ContentControl 可以包含任何类型的公共语言运行时对象(例如字符串或 DateTime 对象)或 UIElement 对象(例如 Rectangle 或 Panel)

    【讨论】:

      猜你喜欢
      • 2013-11-29
      • 2012-07-16
      • 2017-01-12
      • 2015-04-17
      • 2017-12-18
      • 2020-08-19
      • 1970-01-01
      • 2018-04-13
      • 2014-11-15
      相关资源
      最近更新 更多