如何将 WPF 按钮的内容设置为具有多种颜色?

How can I set the Content of a WPF Button to have multiple colors?

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

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

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

您可以将 TextBlock 用作 Button.Content

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

ButtonContentControl 因此

The ContentControl can contain any type of common language runtime object (such as a string or a DateTime object) or a UIElement object (such as a Rectangle or a Panel)