I was just wondering if it would be possible to bind the list of available FontStyle
s and FontWeight
s to a ComboBox
?
For example, to bind the list of fonts to a combobox you can use:
FontComboBox.ItemsSource = Fonts.SystemFontFamilies;
Can I also have something for :
FontStyleComboBox.ItemsSource = ....
FontWeightComboBox.ItemsSource = .... ?
Would it require reflection on the System.Windows.FontWeights
and System.Windows.FontStyles
classes or would there be an easier way than that?
Thanks
For the font families combo:
<ComboBox Name="Families" ItemsSource="{x:Static Fonts.SystemFontFamilies}"/>
For the font styles:
<ComboBox Name="Styles">
<x:Static Member="FontStyles.Normal"/>
<x:Static Member="FontStyles.Italic"/>
<x:Static Member="FontStyles.Oblique"/>
</ComboBox>
And for the font weights:
<ComboBox Name="Weights">
<x:Static Member="FontWeights.Black"/>
<x:Static Member="FontWeights.Bold"/>
<x:Static Member="FontWeights.DemiBold"/>
<x:Static Member="FontWeights.ExtraBlack"/>
<x:Static Member="FontWeights.ExtraBold"/>
<x:Static Member="FontWeights.ExtraLight"/>
<x:Static Member="FontWeights.Heavy"/>
<x:Static Member="FontWeights.Light"/>
<x:Static Member="FontWeights.Medium"/>
<x:Static Member="FontWeights.Normal"/>
<x:Static Member="FontWeights.Regular"/>
<x:Static Member="FontWeights.SemiBold"/>
<x:Static Member="FontWeights.Thin"/>
<x:Static Member="FontWeights.UltraBlack"/>
<x:Static Member="FontWeights.UltraBold"/>
<x:Static Member="FontWeights.UltraLight"/>
</ComboBox>
And now to test:
<TextBlock
Text="This is some text."
FontFamily="{Binding ElementName=Families, Path=SelectedItem}"
FontStyle="{Binding ElementName=Styles, Path=SelectedItem}"
FontWeight="{Binding ElementName=Weights, Path=SelectedItem}"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With