Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Styles - Creating Font template

Tags:

.net

styles

wpf

I'm creating a resources file to be used in our new WPF application. I can create Colour templates as follows:

<SolidColorBrush x:Key="BorderColorBrush" Color="Black"/>
<SolidColorBrush x:Key="NavigationBorderColorBrush" Color="#FF26425D" />
<SolidColorBrush x:Key="ListBorderColorBrush" Color="#FF59593E"/>

but how do i do the same for fonts? ie: a base type font family?

Thanks in advance

like image 233
melspring Avatar asked Apr 28 '26 23:04

melspring


1 Answers

If you want to create your own font, I think WPF could not help to you. But if you want all labels and text was in one format, you could use Style for the Control and TextBlock:

        <Window.Resources>
            <Style TargetType="Control">
                <Setter Property="FontFamily" Value="Courier New" />
                <Setter Property="Foreground" Value="Red" />
            </Style>
            <Style TargetType="TextBlock">
                <Setter Property="FontFamily" Value="Courier New" />
                <Setter Property="Foreground" Value="Red" />
            </Style>
        </Window.Resources>

Because of TextBlock is not a child class of Control, you should do it twice. (Correct me if its wrong)

like image 57
stukselbax Avatar answered Apr 30 '26 12:04

stukselbax