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引 ...
随机推荐
- 【题解】P4247 [清华集训]序列操作(线段树修改DP)
[题解]P4247 [清华集训]序列操作(线段树修改DP) 一道神仙数据结构(DP)题. 题目大意 给定你一个序列,会区间加和区间变相反数,要你支持查询一段区间内任意选择\(c\)个数乘起来的和.对1 ...
- 我的Android进阶之旅------>解决Your project contains error(s),please fix them
在使用eclipse写好Android的代码,代码没有报错.然后想在AVD中运行测试时,弹出错误框,提示信息为: "Your project contains error(s),pleas ...
- 流畅的python学习笔记:第九章:符合python风格的对象
首先来看下对象的表现形式: class People(): def __init__(self,name,age): self.name=name self.a ...
- <raspberry pi > 用树莓派来听落网电台
树莓派放在抽屉里吃灰有半年多了,去年玩了1个月后就没怎么开整了,上个月没工作,刚好有点闲暇,就把树莓派翻出来折腾,刚好碰到落网改版了,想起以前在树莓派论坛看到有网友拿树莓派来听豆瓣电台,代码那时我都下 ...
- 《Python Machine Learning》索引
目录部分: 第一章:赋予计算机从数据中学习的能力 第二章:训练简单的机器学习算法——分类 第三章:使用sklearn训练机器学习分类器 第四章:建立好的训练集——数据预处理 第五章:通过降维压缩数据 ...
- ubuntu上swift开发学习1
学习目的:通过构建一个web应用的实践过程来学习swift.会使用到Perfect框架建立一个web应用(Perfect是swift的一个web框架). 这一篇介绍环境搭建 学习资源: 环境搭建:ht ...
- PHP按照比例随机
有这样的需求,在打开链接的时候,随机(按照项目的某个属性的比例随机)跳转到指定的几个项目的某一个项目页面 比如项目A:80 项目B:20 那么跳转到项目A 的比例为80%,项目B的比例为20% 那么 ...
- ES设置字段搜索权重——Query-Time Boosting
Query-Time Boosting In Prioritizing Clauses, we explained how you could use the boost parameter at s ...
- mybatis传递多个参数值(转)
Mybatis传递多个参数 ibatis3如何传递多个参数有两个方法:一种是使用Map,另一种是使用JavaBean. <!-- 使用HashMap传递多个参数 para ...
- springMVC源代码阅读之servlet部分<一>servlet部分详解
[一]servlet的概念