Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-use-systemfonts.md
T
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04:00

3.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Use SystemFonts 03/30/2017
csharp
vb
system fonts [WPF]
fonts [WPF], system fonts
classes [WPF], SystemFonts
3f46a4ec-2225-408a-8123-8838a8f7057a

How to: Use SystemFonts

This example shows how to use the static resources of the xref:System.Windows.SystemFonts class in order to style or customize a button.

Example

System resources expose several system-determined values as both resources and properties in order to help you create visuals that are consistent with system settings. xref:System.Windows.SystemFonts is a class that contains both system font values as static properties, and properties that reference resource keys that can be used to access those values dynamically at run time. For example, xref:System.Windows.SystemFonts.CaptionFontFamily%2A is a xref:System.Windows.SystemFonts value, and xref:System.Windows.SystemFonts.CaptionFontFamilyKey%2A is a corresponding resource key.

In XAML, you can use the members of xref:System.Windows.SystemFonts as either static properties or dynamic resource references (with the static property value as the key). Use a dynamic resource reference if you want the font metric to automatically update while the application runs; otherwise, use a static value reference.

Note

The resource keys have the suffix "Key" appended to the property name.

The following example shows how to access and use the properties of xref:System.Windows.SystemFonts as static values in order to style or customize a button. This markup example assigns xref:System.Windows.SystemFonts values to a button.

[!code-xamlSystemRes_snip#FontStaticResources]

To use the values of xref:System.Windows.SystemFonts in code, you do not have to use either a static value or a dynamic resource reference. Instead, use the non-key properties of the xref:System.Windows.SystemFonts class. Although the non-key properties are apparently defined as static properties, the run-time behavior of WPF as hosted by the system will reevaluate the properties in real time and will properly account for user-driven changes to system values. The following example shows how to specify the font settings of a button.

[!code-csharpSystemRes_snip#FontResourcesCode] [!code-vbSystemRes_snip#FontResourcesCode]

See also