Answer the question
In order to leave comments, you need to log in
How to create combobox with custom fonts in code?
Application in C# + WPF
There is a combobox
There are custom fonts that are installed in the system. For example "Journal.ttf", "Alex Brush.ttf" It is
necessary to make it so that not all system fonts are displayed in the combobox, but only those that I specify somewhere.
It is also necessary that these fonts are rendered with their own style. That is, to look in the combobox as they look when applied to text, for example.
Something like this, but so that not all system fonts are displayed, but only those selected by me: I
need a programmatic way, since in the future I will save the values \u200b\u200bof the selected fonts from copmbobox to the settings file and apply to different labels.
How to do it?
<ComboBox Style="{StaticResource Combobox}"
Name="Fonts"
Grid.Row="0" />
Answer the question
In order to leave comments, you need to log in
ComboBox elements can be not only strings, but almost anything. For example Label.
<ComboBox>
<ComboBoxItem>
<Label FontFamily="Font1">Font1</Label>
</ComboBoxItem>
<ComboBoxItem>
<Label FontFamily="Font2">Font2</Label>
</ComboBoxItem>
</ComboBox>
Take the FontFamily list and assign it to the Source ComboBox.
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock FontFamily="{Binding}" Text="{Binding Name}" />
<DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Write them down.
combox.Font = new Font(label1.font.name, w, label1.font.style)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question