WPF之触发器
简单触发器
<Window x:Class="WpfApp.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Window.Resources>
<Style x:Key="BigFontButton"><!--命名为大字体-->
<Setter Property="Control.FontFamily" Value=" Times new Roman"></Setter>
<Setter Property="Control.FontSize" Value="32"></Setter>
<Style.Triggers><!--触发器集合-->
<Trigger Property="Control.IsFocused" Value="True"><!--获取焦点触发-->
<Setter Property="Control.Foreground" Value="DarkRed"></Setter><!--触发内容为变红色-->
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<Button Content="Button" Style="{StaticResource BigFontButton}"/> </Grid>
</Window>
结果button获取焦点后 字体变红
<Window x:Class="WpfApp.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp"
mc:Ignorable="d"
Title="Window1" Height="450" Width="800">
<Window.Resources>
<Style x:Key="BigFontButton"><!--命名为大字体-->
<Setter Property="Control.FontFamily" Value=" Times new Roman"></Setter>
<Setter Property="Control.FontSize" Value="32"></Setter>
<Style.Triggers><!--触发器集合-->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Control.IsFocused" Value="True"></Condition>
<Condition Property="Control.IsMouseOver" Value="True"></Condition>
</MultiTrigger.Conditions>
<MultiTrigger.Setters>
<Setter Property="Control.Foreground" Value="Red"></Setter>
</MultiTrigger.Setters>
</MultiTrigger> </Style.Triggers>
</Style>
</Window.Resources>
<StackPanel VerticalAlignment="Center">
<Button Content="Button" Style="{StaticResource BigFontButton}"/>
<TextBox Margin="10" Text="必须满足两个条件才能触发触发器"/>
</StackPanel>
</Window>
事件触发器
<Window x:Class="WpfApp.Window2"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp"
mc:Ignorable="d"
Title="Window2" Height="450" Width="800">
<Window.Resources>
<Style x:Key="EventTrriger">
<Style.Setters>
<Setter Property="Control.FontSize" Value="red"></Setter>
<Setter Property="Control.FontFamily" Value="Yellow"></Setter>
</Style.Setters>
<Style.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="FontSize" To="48"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger><!--路由事件--> </Style.Triggers>
</Style>
</Window.Resources>
<StackPanel>
<Button Name="bt_1" Content="事件触发器" Style="{StaticResource EventTrriger}"/>
</StackPanel>
</Window>
WPF之触发器的更多相关文章
- WPF – 使用触发器
WPF – 使用触发器 WPF提供了很重要的一个东西就是绑定Binding, 它帮助我们做了很多事情,这个我们在WPF学习之绑定这篇里边有讲过.对于Binding我们可以设置其绑定对象,关系,并通过某 ...
- Zara带你快速入门WPF(3)---触发器篇
一.前言 使用触发器,可以动态的改变控件的外观,因为一些事件或属性改变了,把鼠标移动到按钮上,按钮就会改变其外观.通常这些必须写在C#代码中,使用WPF也可以使用XAMl实现,而这只会影响UI. 属性 ...
- WPF中触发器Trigger、MultiTrigger、DataTrigger、MultiDataTrigger、EventTrigger几种
WPF中有种叫做触发器的东西(记住不是数据库的trigger哦).它的主要作用是根据trigger的不同条件来自动更改外观属性,或者执行动画等操作. WPFtrigger的主要类型有:Trigger. ...
- WPF 单个触发器、多个触发器、多条件触发器
Trigger的使用.利用Trigger对象,我们可以接收到属性变化或者事件发生,并据此做出适当的响应.Trigger本身也是支持多种类型的,下面是一个属性Trigger的例子: <Style ...
- WPF中触发器(Trigger、DataTrigger)使用动画最简单的方式EnterActions和ExitsActions
1.当鼠标移入后执行某个动画: <Style TargetType="{x:Type StackPanel}"> <Setter Property="R ...
- WPF DataGrid 触发器
<DataGrid.RowHeaderStyle> <Style TargetType="DataGridRowHeader"> <Style.Tri ...
- WPF 触发器例子
WPF的触发器很强大,这里简单附上触发器的一个小例子,分别用XMAL和CS代码来实现一个功能,鼠标悬停在button上时改变字体颜色 1.XMAL代码如下: <Window x:Class=&q ...
- 《Programming WPF》翻译 第8章 3.Storyboard
原文:<Programming WPF>翻译 第8章 3.Storyboard Storyboard是动画的集合.如果你使用了标记,所有的动画必须要被定义在一个Storyboard中.(在 ...
- WPF与Silverlight对比
1.WPF中控件的肤色可以直接:telerik:StyleManager.Theme=”XXXXX”,不用再导入肤色的dll包.可Silverlight使用系统肤色时,要导入肤色的dll包. WPF引 ...
随机推荐
- AWS:4.VPC
主要介绍 1.Amazon混合云 2.将EC2加入VPC 3.VPC经典场景 4.VPC安全保障 Amazon混合云 : 在公有云的基础上创建私有云 VPC概念 VPC(VPC Virtual Pri ...
- zookeeper_action
连接串 从节点列表本地缓存主节点对未分配的任务,随机分配给从节点(不合理??)从节点保存一个本地待执行任务列表单独的线程对节点已分配任务进行循环 进程p为了获锁——>创建节点znode_/loc ...
- Swift 学习笔记 (闭包)
闭包是可以在你的代码中被传递和饮用的功能性独立模块.Swift中的闭包和C以及Objective-C中的Block很像,和其他语言中的匿名函数也很像. 闭包能捕获和存储定义在其上下文中的任何常量和变量 ...
- GstAppSink简介
Description Appsink is a sink plugin that supports many different methods for making the application ...
- Android databinding 开发参考
1,android studio添加databinding依赖需要注意事项: http://www.zhihu.com/question/33538477?sort=created 2, databi ...
- Maximum Subsequence Sum 【DP】
Given a sequence of K integers { N1, N2, -, NK }. A continuous subsequence is defined to be ...
- HDU4825 Xor Sum —— Trie树
题目链接:https://vjudge.net/problem/HDU-4825 Xor Sum Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- Contiki学习资料
一.官方网站 官网主页:http://contiki-os.org/ 资源和支持:http://contiki-os.org/support.html The Contiki Community: h ...
- Android 7.1 GUI系统-窗口管理WMS-Surface管理(四)
Surface的管理 Surface是窗口能真正显示到物理屏幕上的基础,由surfaceflinger管理,可以通过WindowStateAnimator.java中的变量mDrawState来查看每 ...
- PHPexcel把数据库数据直接转化为excel表格
运行文件 index.php <?php$dir =dirname(__FILE__); //获取当前文件的路径require $dir.'/Classes/phpexcel.php'; // ...