WPF样式
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UC="clr-namespace:WpfApplication1"
xmlns:UC1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<!--
Button控件样式
-->
<Style TargetType="Button">
<Setter Property="Background" Value="Pink"/>
<Setter Property="FontSize" Value="22"/>
</Style>
<!--
XAML的Class
-->
<Style x:Key="mystyle" TargetType="ContentControl">
<Setter Property="Background" Value="Peru"/>
<Setter Property="FontSize" Value="30"/>
</Style> <!--
继承mystyle
-->
<Style x:Key="mystyle2" TargetType="ContentControl" BasedOn="{StaticResource ResourceKey=mystyle}">
<!--覆盖基类样式-->
<Setter Property="Background" Value="Red" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Content="Button" Grid.Row="0"/>
<Button Style="{StaticResource ResourceKey=mystyle}"
Content="XAML的Class" Grid.Row="1"/>
<Button Style="{StaticResource ResourceKey=mystyle2}"
Content="样式的继承mystyle" Grid.Row="2"/>
<Button Content="Button嵌入样式" Grid.Row="3">
<Button.Resources>
<Style TargetType="Button" >
<Setter Property="Background" Value="Coral"></Setter>
</Style>
</Button.Resources>
</Button>
</Grid>
</Window>

<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UC="clr-namespace:WpfApplication1"
xmlns:UC1="clr-namespace:WpfControlLibrary1;assembly=WpfControlLibrary1"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style x:Key="TriggersStyle" TargetType="Label">
<Setter Property="Background" Value="BurlyWood"/>
<Style.Triggers>
<!--Triggers单一条件触发事件 当IsMouseOver的时候,Button颜色变成粉色 -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Pink"/>
</Trigger>
</Style.Triggers>
</Style> <Style x:Key="MultiTriggerStyle" TargetType="Button">
<Setter Property="Background" Value="BurlyWood"/>
<Style.Triggers>
<!--MultiTrigger多条件触发事件 当IsMouseOver后IsPressed时候,字体30号 -->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"></Condition>
<Condition Property="IsPressed" Value="True"></Condition>
</MultiTrigger.Conditions>
<Setter Property="FontSize" Value="30"/>
</MultiTrigger>
</Style.Triggers>
</Style> <Style x:Key="DataTriggerStyle" TargetType="Control">
<Setter Property="Background" Value="Brown"/>
<Style.Triggers>
<!-- 绑定当前的radio单选框,如果按钮选中,触发字体设置 -->
<DataTrigger Binding="{Binding ElementName=radio, Path=IsChecked}" Value="True">
<Setter Property="FontSize" Value="30"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Style="{StaticResource ResourceKey=TriggersStyle}" Content="Triggers"></Label>
<Button Style="{StaticResource ResourceKey=MultiTriggerStyle}" Content="MultiTrigger" Grid.Row="1"></Button>
<RadioButton Style="{StaticResource ResourceKey=DataTriggerStyle}" Name="radio" Content="我要变成20号字" Grid.Row="2"></RadioButton>
</Grid>
</Window>
WPF样式的更多相关文章
- Bootstrap WPF Style,Bootstrap风格的WPF样式
简介 GitHub地址:https://github.com/ptddqr/bootstrap-wpf-style 此样式基于bootstrap-3.3.0,样式文件里的源码行数都是指的这个版本.CS ...
- 写自己的WPF样式 - 窗体
初试WPF样式,感觉还不错.上篇写完了按钮的样式下面写窗体,废话不多说直接上代码: (1)定义一个窗体样式"MyWpfWindow" <Style x:Key="M ...
- C#工具:Bootstrap WPF Style,Bootstrap风格的WPF样式
简介 GitHub地址:https://github.com/ptddqr/bootstrap-wpf-style 此样式基于bootstrap-3.3.0,样式文件里的源码行数都是指的这个版本.CS ...
- WPF样式(Style)入门
原文:WPF样式(Style)入门 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_34802416/article/details/78231 ...
- WPF样式——经典博客
WPF样式博客:http://www.cnblogs.com/luluping/archive/2011/05/06/2039498.html
- WPF样式学习三
SnapsToDevicePixels 获取或设置在呈现过程,该值来确定呈现此元素是否应使用特定于设备的像素设置. 这是一个依赖项属性. true ,如果元素应以符合呈现到设备像素;否则, false ...
- WPF样式与触发器(3)
WPF中的各类控件元素, 都可以自由的设置其样式. 诸如: 字体(FontFamily) 字体大小(FontSize) 背景颜色(Background) 字体颜色(Foreground) 边距(Mar ...
- 【转】【WPF】WPF样式(Style)—触发器
样式(Styles)由三部分构成:设置器(Setter).触发器(Triggers).资源(Resources). (1)触发器,让样式的使用更加准确.灵活和高效. (2)触发器(Triggers)主 ...
- WPF 样式和行为
样式(style):组织和重用格式化选项的重要工具,将细节如边距.字体.字号等信息封装起来,然后再需要的地方通过属性来应用样式. 行为(behavior):封装一些通用的UI行为,如拖动,缩放元素的代 ...
- WPF样式资源文件简单运用
WPF通过资源来保存一些可以被重复利用的样式,下面的示例展示了简单的资源样式文件的使用: 一.xaml中定义资源及简单的引用 <Window.Resources > <!--wpf窗 ...
随机推荐
- 使用json存储结构化数据
从文件中读写字符串很容易.数值就要多费点儿周折,因为read ()方法只会返回字符串,应将其传入int()这样的函数,就可以将'123'这样的字符串转换为对应的数值 123.当你想要保存更为复杂的数据 ...
- Internet与www的关系
Internet是把分布于世界各地不同结构的计算机网络用各种传输介质相互连接起来的网络. 因此,被称为网络的网络.Internet提供的主要服务有万维网(WWW.)文件传输(FTP.)电子邮件(E-m ...
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
Here is this topic’s background: I defined a custom View which extends FrameLayout and contains a Te ...
- Python 命名空间
通俗的来说,Python中所谓的命名空间可以理解为一个容器.在这个容器中可以装许多标识符.不同容器中的同名的标识符是不会相互冲突的.理解python的命名空间需要掌握三条规则: 第一,赋值(包括显式赋 ...
- 3.6---双栈排序(CC150)
答,课本上的方法比较好. public static Stack<Integer> sort(Stack<Integer> s) { Stack<Integer> ...
- 2.3---删除链表的结点,不提供头结点(CC150)
这里,注意如果是尾结点,那么无解. public class Solution { public void deleteNode(ListNode node) { //利用李代桃僵 // // if( ...
- ffmpeg解码视频流
//初始化.注册编解码器 avcodec_init(); av_register_all(); avformat_network_init(); //选取测试文件 char* FileName = & ...
- sed使用的并不是完全的正则表达式
经过实验发现,命令sed 's/pattern/replacement/' file中,pattern使用的并不是完全的正则表达式,而如果想使用正则表达式,需要使用sed命令的 -r 选项: sed ...
- JavaScript——Prototype详探
用过JavaScript的同学们肯定都对prototype如雷贯耳,但是这究竟是个什么东西却让初学者莫衷一是,只知道函数都会有一个prototype属性,可以为其添加函数供实例访问,其它的就不清楚了, ...
- ios iphone6 Plus 的适配问题
最近更新一个老程序,发现在iphone6 plus上用nslog打印出的screen 的frame还是320*568, 不是414*736, 查了一下,原来需要设置iphone6 plus的启动画面才 ...