How to set the default font for a WPF application? How to set the default font for a WPF application? wpf wpf

How to set the default font for a WPF application?


Assuming your Window subclasses don't override DefaultStyleKey, you can simply add it to your Window style, since TextElement.FontFamilyProperty is an inherited property:

<Style TargetType="{x:Type Window}">     <Setter Property="FontFamily" Value="Segoe UI" />             </Style> 

You also need to add the following to your App constructor after the InitializeComponent call:

FrameworkElement.StyleProperty.OverrideMetadata(typeof(Window), new FrameworkPropertyMetadata{    DefaultValue = FindResource(typeof(Window))});

How it works: After the App object finishes initializing, the Window style specified therein is made the default style for all windows.


Most of proposed solutions didn't work for me. My simple solution:

Add this to App.xaml:

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

Add this in your MainWindow constructor (after InitializeComponent):

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


One simple way to do it programmatically:

public MainWindow(){    this.FontFamily = new FontFamily("Segoe UI");}