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

    方式一、Window.Resources
    <Window.Resources>
        <Style TargetType="控件类型" x:Key="样式名">
            <Setter Property="属性名"  Value="属性值"/>
        </Style>      
    例如:
        <Style TargetType="Button">
            <Setter Property="Background" Value="Red" />
        </Style>
    </Window.Resources>

    调用样式
    <Button Style="{StaticResource 样式名}">

    样式事件
    <EventSetter Event="控件类型.事件类型" Handler="事件名" />
    例如:
    <EventSetter Event="TextBlock.MouseEnter" Handler="tb_MouseEnter" />

    样式继承
    <Style x:Key="样式名" BasedOn="{StaticResource 基类样式名}">

    样式触发器
    <Style TargetType="控件类型">
        <Style.Triggers>
            <Trigger Property="Control.触发类型" Value="True">
                <Setter Property="Control.属性名" Value="属性值" />
            </Trigger>
        </Style.Triggers>
    </Style>
    例如
    <Style TargetType="Button">
        <Trigger Property="Control.IsFocused" Value="True">
            <Setter Property="Control.Foreground" Value="DarkRed" />
        </Trigger>
    </Style>

    二、Application.Resources
    <Application.Resources>
        <Style TargetType="控件类型" x:Key="样式名">
            <Setter Property="属性名"  Value="属性值"/>
        </Style>
    </Application.Resources>

    调用外部资源
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/程序集;component/路径.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

    三、后台调用资源
    ResourceDictionary rd= new ResourceDictionary();
    rd.Source = new Uri("程序集;component/路径.xaml", UriKind.Relative);
    调用样式
    SolidColorBrush blueBrush =(SolidColorBrush)rd["BlueBrush"];


    <!--使其不引用事先定义的样式-->
    <控件 Style="{x:Null}">
    例如
    <Button Style="{x:Null}">

  • 相关阅读:
    docker学习构建镜像---第三章节
    docker学习端口映射---第二章节
    推荐一个小而美的Python代码格式化工具
    Bi-LSTM+CRF在文本序列标注中的应用
    大数据分析师到底在干嘛
    Pytorch实现的语义分割器
    Python大数据与机器学习之NumPy初体验
    python数据分析工具——Pandas、StatsModels、Scikit-Learn
    Python修改paramiko模块开发运维审计保垒机
    Python数据预处理:使用Dask和Numba并行化加速
  • 原文地址:https://www.cnblogs.com/sntetwt/p/8888688.html
Copyright © 2011-2022 走看看