Home > Back-end >  For WPF default System Font how can I specify the default system font in a resource dictionary
For WPF default System Font how can I specify the default system font in a resource dictionary

Time:05-10

In a resource dictionary, is there a way to declare that the default System FontFamily is what is desired without having to declare a specific System FontFamily (i.e. Segoe UI) ?

If have have the following declaration:

<FontFamily x:Key="<some key string>" > xxx </FontFamily>

What do I substitute for the xxx to specify the default System FontFamily (System.Media.Windows)?

CodePudding user response:

In a resource dictionary, is there a way to declare that the default System FontFamily is what is desired without having to declare a specific System FontFamily (i.e. Segoe UI) ?

Short answer: No. Not in XAML.

You could create your resource programmatically though:

Resources.Add("someKey", SystemFonts.CaptionFontFamily);

Or simply use the existing resource(s) from the SystemFonts class directly without creating your own resources, e.g.:

<TextBlock Text="Sample text..." FontFamily="{x:Static SystemFonts.CaptionFontFamily}" />

CodePudding user response:

<FontFamily.FamilyNames>
    <System:String x:Key="en-US">Comic San Serif</System:String>
</FontFamily.FamilyNames>

More details here

  • Related