• 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}">

  • 相关阅读:
    做汉堡
    作业2结对子
    软件开发流程阅读《构建之法》 第5.5 第6 第7章
    自动生成四则运算
    修改过的四则运算
    【暴力DP】[Dota1004]受折磨的灵魂(TormentedSoul)
    【Blog】Start My Journey In Cnblogs!
    【DP+ShortPath】[Dota1000]德鲁伊(Dyrad)
    【Watery DP】[Dota1002]光之守卫(Gandolf)
    【DP】[Dota1003]育母蜘蛛(BroodMother)
  • 原文地址:https://www.cnblogs.com/sntetwt/p/8888688.html
Copyright © 2020-2023  润新知