zoukankan      html  css  js  c++  java
  • WPF Style设置的二种方法

    效果如下:

     

     

    案例一描述:

    TargetType 设置所有TextBlock样式

        <s:SurfaceWindow.Resources>

        <Style TargetType="{x:Type TextBlock}">

            <Setter Property="FontFamily" Value="Segoe Black" />

            <Setter Property="HorizontalAlignment" Value="Center" />

            <Setter Property="FontSize" Value="12pt" />

            <Setter Property="Foreground" Value="#777777" />

                <Setter Property="Background" Value="Yellow"/>

            </Style>

        </s:SurfaceWindow.Resources>

       

        <Grid>

            <TextBlock >你好!</TextBlock>

        </Grid>

     

    案例二描述:

    通过key-StaticResource方式获取style中设置的参数:

    注意:不同于TargetType的是key-StaticResource 必须用“Control.FontFamily”的方式来设置。

        <s:SurfaceWindow.Resources>

            <Style x:Key="style1">

                <Setter Property="Control.FontFamily" Value="Segoe Black" />

                <Setter Property="Control.HorizontalAlignment" Value="Center" />

                <Setter Property="Control.FontSize" Value="12pt" />

                <Setter Property="Control.Foreground" Value="#777777" />

                <Setter Property="Control.Background" Value="Yellow"/>

            </Style>

        </s:SurfaceWindow.Resources>

        <Grid>

            <Label Content="你好!" Style="{StaticResource style1}"></Label>

        </Grid>

  • 相关阅读:
    XLS导出的服务器端配置方式
    SQLSERVER2008 内存占用高的处理方式
    word定义多级列表
    SQL Server替换特殊字符
    php和mysql两种不同方式的分割字符串和类型转换
    tp杂记
    MySql数据库 主从复制/共享 报错
    the server ssl certificate failed to verify
    loaded some nib but the view outlet was not set(转载)
    xcode7 调用相册权限无提示
  • 原文地址:https://www.cnblogs.com/DeepBlues/p/2915923.html
Copyright © 2011-2022 走看看