* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
3.3 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 |
|
|
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 [!INCLUDETLA2#tla_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 [!INCLUDETLA2#tla_winclient] 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]