Kaganapan
Mar 17, 9 PM - Mar 21, 10 AM
Sumali sa serye ng meetup upang bumuo ng mga scalable AI solusyon batay sa mga kaso ng paggamit ng tunay na mundo sa mga kapwa developer at eksperto.
Magparehistro naHindi na suportado ang browser na ito.
Mag-upgrade sa Microsoft Edge para samantalahin ang mga pinakabagong tampok, update sa seguridad, at teknikal na suporta.
This example demonstrates how to use system-defined resources. System resources are provided by WPF and allow access to operating system resources, such as fonts, colors, and icons. System resources expose several system-defined values as both resources and properties to help you create visuals that are consistent with Windows.
Use the SystemFonts class to reference the fonts used by the operating system. This class contains 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, CaptionFontFamily is a SystemFonts value, and CaptionFontFamilyKey is a corresponding resource key.
The following example shows how to access and use the properties of SystemFonts as static values to style or customize a text block:
<TextBlock FontSize="{x:Static SystemFonts.SmallCaptionFontSize}"
FontWeight="{x:Static SystemFonts.SmallCaptionFontWeight}"
FontFamily="{x:Static SystemFonts.SmallCaptionFontFamily}"
Text="Small Caption Font">
</TextBlock>
To use the values of SystemFonts in code, you don't 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 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:
var myButton = new Button()
{
Content = "SystemFonts",
Background = SystemColors.ControlDarkDarkBrush,
FontSize = SystemFonts.IconFontSize,
FontWeight = SystemFonts.MessageFontWeight,
FontFamily = SystemFonts.CaptionFontFamily
};
mainStackPanel.Children.Add(myButton);
Dim myButton = New Button() With
{
.Content = "SystemFonts",
.Background = SystemColors.ControlDarkDarkBrush,
.FontSize = SystemFonts.IconFontSize,
.FontWeight = SystemFonts.MessageFontWeight,
.FontFamily = SystemFonts.CaptionFontFamily
}
mainStackPanel.Children.Add(myButton)
System font metrics can be used as either static or dynamic resources. Use a dynamic resource if you want the font metric to update automatically while the application runs; otherwise, use a static resource.
Note
Dynamic resources have the keyword Key
appended to the property name.
The following example shows how to access and use system font dynamic resources to style or customize a text block:
<TextBlock FontSize="{DynamicResource {x:Static SystemFonts.SmallCaptionFontSize}}"
FontWeight="{DynamicResource {x:Static SystemFonts.SmallCaptionFontWeight}}"
FontFamily="{DynamicResource {x:Static SystemFonts.SmallCaptionFontFamily}}"
Text="Small Caption Font">
</TextBlock>
Use the SystemParameters class to reference system-level properties, such as the size of the primary display. This class 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.
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"
Height="{x:Static SystemParameters.CaptionHeight}"
Width="{x:Static SystemParameters.IconGridWidth}"
Content="System Parameters">
</Button>
To use the values of SystemParameters in code, you don't 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 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 set the width and height of a button by using SystemParameters values:
var myButton = new Button()
{
Content = "SystemParameters",
FontSize = 8,
Background = SystemColors.ControlDarkDarkBrush,
Height = SystemParameters.CaptionHeight,
Width = SystemParameters.CaptionWidth,
};
mainStackPanel.Children.Add(myButton);
Dim myButton = New Button() With
{
.Content = "SystemParameters",
.FontSize = 8,
.Background = SystemColors.ControlDarkDarkBrush,
.Height = SystemParameters.CaptionHeight,
.Width = SystemParameters.CaptionWidth
}
mainStackPanel.Children.Add(myButton)
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.
Note
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. This XAML example sizes a button by assigning SystemParameters values to the button's width and height.
<Button FontSize="8"
Height="{DynamicResource {x:Static SystemParameters.CaptionHeightKey}}"
Width="{DynamicResource {x:Static SystemParameters.IconGridWidthKey}}"
Content="System Parameters">
</Button>
Feedback sa .NET Desktop feedback
Ang .NET Desktop feedback ay isang open source na project. Pumili ng link para magbibigay ng feedback:
Kaganapan
Mar 17, 9 PM - Mar 21, 10 AM
Sumali sa serye ng meetup upang bumuo ng mga scalable AI solusyon batay sa mga kaso ng paggamit ng tunay na mundo sa mga kapwa developer at eksperto.
Magparehistro naPagsasanay
Module
Design consistent .NET MAUI XAML pages by using shared resources - Training
Learn how to use static and dynamic shared resources to build a .NET Multi-platform App UI (MAUI) user interface. And see how styles can make the user interface both consistent and accessible.
Dokumentasyon
XAML resources overview - WPF .NET
Learn what a Windows Presentation Foundation (WPF) resource is. WPF provides a system that allows to you create, reference, and reuse resources.
How to define and reference a resource - WPF .NET
Learn how to define and reference Windows Presentation Foundation (WPF) resources through XAML and code.
StaticResource Markup Extension - WPF .NET Framework
Provides a value for any XAML property attribute by looking up a reference to an already defined resource.
Resources - WPF .NET Framework
Learn about Windows Presentation Foundation (WPF) resources, which are objects that can be reused in different places in your applications.