Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SystemFonts Class

Contains properties that expose the system resources that concern fonts.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public static class SystemFonts
public final class SystemFonts
public final class SystemFonts
You cannot use this managed class in XAML.

This example shows how to use the static resources of SystemFonts in order to style or customize a button.

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. 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 runtime. For example, CaptionFontFamily is a SystemFonts value and CaptionFontFamilyKey is a corresponding resource key.

In XAML, you can use the members of SystemFonts as either a static property usage, or a 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.

NoteNote:

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

The following example explains how to access and use the properties of SystemFonts as a static value in order to style or customize a button. This markup example assigns SystemFonts values to a button.

<Button Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="3"      
     FontSize="{x:Static SystemFonts.IconFontSize}"
     FontWeight="{x:Static SystemFonts.MessageFontWeight}"
     FontFamily="{x:Static SystemFonts.CaptionFontFamily}">
     SystemFonts
</Button>

To use the values of 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 SystemFonts class. Although the non-key properties are apparently defined as static properties, the runtime behavior of WPF as hosted by the system will reevaluate the properties in realtime, and will properly account for user-driven changes to system values. The following example shows how to set the font settings of a button.

Button btncsharp = new Button();
btncsharp.Content = "SystemFonts";
btncsharp.Background = SystemColors.ControlDarkDarkBrush;
btncsharp.FontSize = SystemFonts.IconFontSize;
btncsharp.FontWeight = SystemFonts.MessageFontWeight;
btncsharp.FontFamily = SystemFonts.CaptionFontFamily;
cv1.Children.Add(btncsharp);

More Code

How to: Use System Fonts Keys

System resources expose a number of system metrics as resources to help developers create visuals that are consistent with system settings. SystemFonts is a class that contains both system font values and system font resources that bind to the values—for example, CaptionFontFamily and CaptionFontFamilyKey.

System.Object
  System.Windows.SystemFonts

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft