WPF global font size WPF global font size wpf wpf

WPF global font size


I'd do it this way:

<Window.Resources>        <Style TargetType="{x:Type Control}" x:Key="baseStyle">            <Setter Property="FontSize" Value="100" />        </Style>        <Style TargetType="{x:Type Button}" BasedOn="{StaticResource baseStyle}"></Style>        <Style TargetType="{x:Type Label}" BasedOn="{StaticResource baseStyle}"></Style>        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource baseStyle}"></Style>        <Style TargetType="{x:Type ListView}" BasedOn="{StaticResource baseStyle}"></Style>        <!-- ComboBox, RadioButton, CheckBox, etc... -->    </Window.Resources>

That way, if I want to change ALL the controls, I'd just have to change the "baseStyle" style, the rest would just inherit from it. (That's what BasedOn property those, you can also extend the base style if you create other setters inside of the inherited style)


FontSizeProperty is inherited from Parent Control. So you just need to change FontSize of your main window.

If you don't need dynamic behaviour this should work:

Add a style for Window to your ResourceDictionary

<Style TargetType="{x:Type Window}">     <Setter Property="FontSize" Value="15" /></Style>

Apply the style to your main form (will not be applied implicit because its a derived type)

 Style = (Style)FindResource(typeof (Window));


<Window> has a property FontSize.

So you can set desired fontsize in element if you want to change the fontsize in all the elements within that window.

<Window FontSize="12"></Window>