欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

wpf - Use SystemParameters to Style or Customize

程序员文章站 2022-06-07 14:25:57
...

SystemParameters has properties that you can query system settings. See reference [2] 

We will see an example that does customization on a button, which has some properties's values coming from the SystemParameters.

Here is the source code, which the containing Grid, Window, and etc.. 


<Window x:Class="UseSystemParameters.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="9*"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Button
            FontSize="8"
            Margin="10, 10, 5, 5" Grid.Row="0"
            HorizontalAlignment="Left"
            Height="{x:Static SystemParameters.CaptionHeight}"
            Width="{x:Static SystemParameters.IconGridWidth}"
            >
            SystemParameters
        </Button>
        <StackPanel x:Name="cv2"  Grid.Row="1"></StackPanel>
    </Grid>
</Window>
and you are not limited to use just the xaml, you are encourage to use the Code-behind code, and it is just as simple as get the Static Property out of something.. 



using System.Windows;
using System.Windows.Controls;


namespace UseSystemParameters
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            Button btncsharp = new Button();
            btncsharp.Content = "SystemParameters";
            btncsharp.FontSize = 8;
            btncsharp.Background = SystemColors.ControlDarkDarkBrush;
            btncsharp.Height = SystemParameters.CaptionHeight;
            btncsharp.Width = SystemParameters.IconGridHeight;
            btncsharp.HorizontalAlignment = HorizontalAlignment.Left;
            btncsharp.Margin = new Thickness(10, 10, 5, 5);
            cv2.Children.Add(btncsharp);
        }
    }
}


References:



转载于:https://my.oschina.net/u/854138/blog/131003