Compartir a través de


How to: Use SystemParameters

This example shows how to access and use the properties of SystemParameters in order to style or customize a button.

Example

System resources expose several system based settings as resources in order to help you create visuals that are consistent with system settings. SystemParameters is a class that contains both system parameter value properties, and resource keys that bind to the values. For example, FullPrimaryScreenHeight is a SystemParameters property value and FullPrimaryScreenHeightKey is the corresponding resource key.

In XAML, you can use the members of SystemParameters 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 system based value to update automatically while the application runs; otherwise, use a static reference. Resource keys have the suffix Key appended to the property name.

The following example shows how to access and use the static values of SystemParameters to style or customize a button. This markup example sizes a button by applying SystemParameters values to a button.

<Button FontSize="8" Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="5"      
     HorizontalAlignment="Left" 
     Height="{x:Static SystemParameters.CaptionHeight}"
     Width="{x:Static SystemParameters.IconGridWidth}">
     SystemParameters
</Button>

To use the values of SystemParameters in code, you do not have to use either static references or dynamic resource references. Instead, use the values of the SystemParameters 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 width and height of a button by using SystemParameters values.

Button btncsharp = new Button();
btncsharp.Content = "SystemParameters";
btncsharp.FontSize = 8;
btncsharp.Background = SystemColors.ControlDarkDarkBrush;
btncsharp.Height = SystemParameters.CaptionHeight;
btncsharp.Width = SystemParameters.IconGridWidth;
cv2.Children.Add(btncsharp);

See Also

Tasks

How to: Paint an Area with a System Brush
How to: Use SystemFonts
How to: Use System Parameters Keys

Reference

SystemParameters

Other Resources

Resources How-to Topics
Resources Samples
Button Styles Sample