wpf - Use SystemParameters to Style or Customize


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值