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

    1、内联样式
    <TextBlock FontSize="20" Foreground="Blue">好啊</TextBlock>


    2、页面样式
    <Button Height="20" Margin="0,78,445,213>按钮1</Button>
    <Button Width="50" Height="20" Margin="0,116,453,175">按钮2</Button>

    <Window.Resources>
    <Style TargetType="Button" x:Key="MyStyle">
    <Setter Property="Foreground" Value="Blue"></Setter>
    <Setter Property="FontSize" Value="30"></Setter>
    </Style>
    </Window.Resources>

    应用特性名称样式:
    在样式中添加x:key属性
    <Style TargetType="Button" x:Key="MyStyle">
    <Setter Property="Foreground" Value="BlanchedAlmond"></Setter>
    <Setter Property="FontSize" Value="30"></Setter>
    </Style>

    然后应用该样式 <Button Height="20" Margin="0,78,445,213" Style="{StaticResource MyStyle}">按钮1</Button>

    3、全局样式
    在App.xaml中添加
    <Application.Resources>
    <Style TargetType="Button" x:Key="MyStyle">
    <Setter Property="Foreground" Value="Blue"></Setter>
    <Setter Property="FontSize" Value="30"></Setter>
    </Style>
    </Application.Resources>

    4、外部样式
    新建Dictionary1.xaml文件
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style TargetType="Button" x:Key="MyStyle">
    <Setter Property="Foreground" Value="Blue"></Setter>
    <Setter Property="FontSize" Value="30"></Setter>
    </Style>
    </ResourceDictionary>

    在引用页面添加
    <Window.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="Dictionary1.xaml"></ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Window.Resources>

  • 相关阅读:
    HDU 1009 FatMouse' Trade
    python正则表达式
    Python学习week5
    Python学习week4
    Python学习week3
    Python学习week2
    Python学习week1
    生活的艰辛(最小割,最大密度子图)
    最大获利(最小割,最大权闭合图,最大密度子图)
    最大密度子图
  • 原文地址:https://www.cnblogs.com/Benjamin/p/3870620.html
Copyright © 2011-2022 走看看