zoukankan      html  css  js  c++  java
  • WPF4.5 Cockbook Chapter8(Style, Triggers and Control Template)

    Style

    1:styles是一组setter和trigger的单个object,常被定义为资源使用。用来设置target元素的一组属性。Setter用来决定那个属性需要有那个值。属性必须为DP。

    2:TargetType可以是任何type,甚至是custom type和derived type。如果TargetType是Button则代表只能应用于<Button>或者任何继承自<Button>的元素,否则抛出异常。(TargetType虽然不强制写,但是指定特定的元素应用style对代码维护有好处)。

    3:style一般需要TargetType属性来表达应用到的元素的类型。

    4:style里是一组<setter>来设置应用该style的元素的property

    5:style可以inherit其他style,从而简化重复设置属性,BasedOn属性用来继承其他style,注意base style有TargetType,继承style也要有TargetType。

    好的practice是不超过两层的style继承。

    6:style的Complex property设置:

    View Code
    <Setter property="Effect">
        <Setter.Value>
            <dropShadowEffect Color="Red"/>
        <Setter.Value/>
    <Setter/>

    7:对于属性的设置,遵循DP priority system原则。直接修改属性比同属性的style设置优先级高

    View Code
    <Button Content="=" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" Style="{StaticResource operatorStyle}">
                <Button.Effect>
                    <DropShadowEffect Color="Green" />
                </Button.Effect>
            </Button>

    8:Place to apply style:

    一个元素要应用一个style资源,只要在其后面加上style属性=那个resource就好

    其他还有一些可以加载style的属性(书290)

  • 相关阅读:
    nvidia-smi电源显示ERR (Pwr:Usage ERR)
    阿里云windows安装ftp
    ansible常用模块
    ansible playbook
    ansible Inventory
    ansible安装
    ansible命令
    ansible配置文件
    js插件中提示框含有 或者<br/>显示不成换行怎么办,改样式
    [转] react项目安装及运行
  • 原文地址:https://www.cnblogs.com/shawnzxx/p/2953576.html
Copyright © 2011-2022 走看看