How to set the default font for a WPF application?

后端 未结 6 745
野的像风
野的像风 2020-12-04 11:16

I want to be able to define a font family for my WPF application. Preferably using a resource dictionary as a theme referenced from App.xaml. I\'ve tried creati

6条回答
  •  孤街浪徒
    2020-12-04 11:51

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

     
    

    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.

提交回复
热议问题