I’m struggling to get some finer layout issues working on a WPF button, essentially I’m trying to centre the text inside the button? At the moment I dynamically set several buttons in code with something similar to
button1.Content = (option1 != 0.0)
? option1.ToString() + "\n" + "Centre"
: string.Empty;
button2.Content = (option2 != 0.0)
? option2.ToString() + "\n" + "Quite"
: string.Empty;
button3.Content = (option3 != 0.0)
? option.ToString() + "\n" + "Not"
: string.Empty;
and in XAML both vertical and horizontal content alignment is centre?
<Button Height="30" HorizontalAlignment="Left" Margin="254,0,0,0" Name="button1"
VerticalAlignment="Top" Width="50" Click="button_Click"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontSize="10"
FontStretch="SemiCondensed"/>
but this doesn’t give me the layout I desire, (see below)

-
How do get both the values on top to be centred and the text on the bottom to be centred?
-
If I wanted the bottom text to have font size 10 bold and the top to be font size 14 normal – how do I do that?
Many thanks
I think the easiest way is to use two Textblocks inside the Button and to setup databindings.
please also read MVVM / INotifyPropertychanged tutorials if you don’t already know this patterns (because my example does not implement this interface, the content of the buttonts will not refresh if you change a TextX property)