Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I would like the Content of my WPF Button to use multiple colors like, e.g.:

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

I see that I can't use multiple Runs like in a TextBlock - what is the proper method for achieving this effect?

like image 546
Conrad Avatar asked Sep 03 '25 09:09

Conrad


1 Answers

You can use TextBlock as Button.Content

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

Button is ContentControl and as such

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)

like image 192
dkozl Avatar answered Sep 05 '25 01:09

dkozl