zoukankan      html  css  js  c++  java
  • wpf 样式

    wpf 样式

    wpf的样式与html中的css作用基本一致,都是用作样式重用的

    样式使用的标签是 Window.Resources ,样式标签是 Window 标签的子标签

    样式的命名使用: x:Key="样式名称" 

    使用样式使用 {StaticResource 样式名称} 或者 {DynamicResource 样式名称} 

    • StaticResource 静态样式
    • DynamicResource 动态样式

    静态样式在程序启动时候就固定了,动态样式可以在程序启动后用代码修改样式

    <Window>
        <Window.Resources>
            <LinearGradientBrush x:Key="brush1">
                <GradientStop Offset="0.3" Color="Yellow"/>
                <GradientStop Offset="0.7" Color="Brown"/>
            </LinearGradientBrush>
        </Window.Resources>
        <StackPanel>        
            <Rectangle Height="100" Stroke="Pink" StrokeThickness="20" Fill="{StaticResource brush1}"/>        
            <Button x:Name="button1" Content="Replace Brush" Height="100" Click="OnReplaceBrush"/>
        </StackPanel>
    </Window>

    StyleSetter

    如果字体写一个标签,字体颜色又写一个标签,代码量会特别大,调用也会特别麻烦,使用Style调用起来会比较方便

     Style 标签的属性

    • TargetType 表示标签类型,如:按钮 文本框...
    • x:Key 标签名称

    setter 标签的属性

    • Property 样式
    • Value 样式值
    <Style TargetType="Button" x:Key="btn1">
        <Setter Property="Background" Value="Red"></Setter>
    </Style>

    多层样式

    样式可以指定父类,算是继承,子样式继承父样式的所有样式,子样式可以对父级样式进行修改

    使用 Style 的 BasedOn 属性设置父级样式

    <Style TargetType="Button" x:Key="Btn1">
        <Setter Property="Background" Value="Red"></Setter>
        <Setter Property="FontSize" Value="50px"></Setter>
    </Style>
    <Style x:Key="Btn2" TargetType="Button" BasedOn="{StaticResource Btn1}">
        <Setter Property="FontSize" Value="10px"></Setter>
    </Style>

     

  • 相关阅读:
    js正则表达式
    js正则表达式校验非负浮点数:^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$
    js正则表达式校验非正整数:^((-d+)|(0+))$
    读书笔记--第三章
    phpmyadmin创建数据库无权限
    读书笔记--第二章
    读书笔记--第一章 信息收集
    CTF-1-web安全
    kali优化配置(4)---被动信息收集
    以太坊私有链搭建
  • 原文地址:https://www.cnblogs.com/sunhouzi/p/12400562.html
Copyright © 2011-2022 走看看