如何:使用系统参数键How to: Use System Parameters Keys

系统资源将多个系统规格以资源的形式公开,以帮助开发人员创建与系统设置一致的视觉效果。System resources expose a number of system metrics as resources to help developers create visuals that are consistent with system settings. SystemParameters 是一个类,包含系统参数值和绑定到这些值的资源键 — 例如,FullPrimaryScreenHeightFullPrimaryScreenHeightKeySystemParameters is a class that contains both system parameter values and resource keys that bind to the values—for example, FullPrimaryScreenHeight and FullPrimaryScreenHeightKey. 系统参数规格可用作静态或动态资源。System parameter metrics can be used as either static or dynamic resources. 如果希望参数规格在应用程序运行时自动更新,请使用动态资源;否则,请使用静态资源。Use a dynamic resource if you want the parameter metric to update automatically while the application runs; otherwise use a static resource.

备注

动态资源具有关键字密钥追加到属性名称。Dynamic resources have the keyword Key appended to the property name.

以下示例演示如何访问和使用系统参数动态资源来设计按钮样式或自定义按钮。The following example shows how to access and use system parameter dynamic resources to style or customize a button. XAMLXAML示例调整按钮大小分配SystemParameters为按钮的宽度和高度的值。This XAMLXAML example sizes a button by assigning SystemParameters values to the button's width and height.

示例Example

<Style x:Key="SimpleParam" TargetType="{x:Type Button}">
    <Setter Property = "Height" Value= "{DynamicResource {x:Static SystemParameters.CaptionHeightKey}}"/>
    <Setter Property = "Width" Value= "{DynamicResource {x:Static SystemParameters.IconGridWidthKey}}"/>
</Style>

请参阅See also