第17章 控件模版(4)——事件触发器
来源:互联网 发布:研究生小论文数据造假 编辑:程序博客网 时间:2024/06/06 13:15
一、自定义按钮模版xaml代码
<Window 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:ButtonTemplate" xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" x:Class="ButtonTemplate.MainWindow" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <ControlTemplate x:Key="ButtonTemplate" TargetType="{x:Type Button}"> <Border BorderBrush="Orange" BorderThickness="3" CornerRadius="2" Background="Red" TextBlock.Foreground="White" Name="Border"> <Grid> <Rectangle Name="FocusCue" Visibility="Hidden" Stroke="Black" StrokeThickness="1" StrokeDashArray="1 2" SnapsToDevicePixels="True" ></Rectangle> <ContentPresenter RecognizesAccessKey="True" Margin="{TemplateBinding Padding}"></ContentPresenter> </Grid> </Border> <ControlTemplate.Triggers> <EventTrigger RoutedEvent="MouseEnter"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" To="Blue" Duration="0:0:1" AutoReverse="True" RepeatBehavior="Forever"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> <EventTrigger RoutedEvent="MouseLeave"> <BeginStoryboard> <Storyboard> <ColorAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="Background.Color" Duration="0:0:0.5"></ColorAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> <Trigger Property="IsPressed" Value="True"> <Setter TargetName="Border" Property="Background" Value="IndianRed" /> <Setter TargetName="Border" Property="BorderBrush" Value="DarkKhaki" /> </Trigger> <Trigger Property="IsKeyboardFocused" Value="True"> <Setter TargetName="FocusCue" Property="Visibility" Value="Visible" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Window.Resources> <StackPanel Margin="10"> <Button Margin="10" Padding="5" Template="{StaticResource ButtonTemplate}" Name="cmdOne">A Simple Button with a Custom Template</Button> <Button Margin="10" Padding="5" Template="{StaticResource ButtonTemplate}" Name="cmdTwo">Another Button with a Custom Template</Button> </StackPanel></Window>二、效果显示
三、特殊说明
①属性触发器和事件触发器都可以添加动画,但一般用事件触发器设置动画
②动画还可实现以下效果:
1)显示与隐藏元素。为此,需要改变控件模版中元素的Opacity属性。
2)改变形状或位置。使用Translateform对象调整元素位置。使用ScaleTransform或RotateTransform旋转元素。
3)改变光照或着色。为此,需使用改变绘制背景的画刷的动画。
0 0
- 第17章 控件模版(4)——事件触发器
- 第17章 控件模版(3)——属性触发器
- 第17章 控件模版(2)——模版绑定
- 第17章 控件模版(1)——模版的创建与使用
- 第17章 控件模版(5)——组织模版资源概述
- 第17章 控件模版(6)——通过样式应用模版
- 第17章 控件模版(7)——通过样式自动应用模版
- 第17章 控件模版(8)——动态换肤
- 第13章 触发器
- Oracle触发器4-数据库事件触发器
- 模版——函数模版、类模版
- 犀牛——第17章 事件处理
- OpenCV2马拉松第13圈——模版匹配
- 事件触发器
- 第5章 路由事件(4)——附加路由事件
- 【C++ Primer】第16章 模版与泛型模版
- 第15章 动画基础(2)——故事板、触发器
- 【木头Cocos2d-x 035】我是定时器(第04章)—停止update和触发器
- Ubuntu中MySQL学习笔记00
- HDU 5412 CRB and Queries(整体二分 | CDQ分治)
- HDU 5732 Subway(树同构)
- 简单的二分查找条件
- c/c++ 练习笔记
- 第17章 控件模版(4)——事件触发器
- 226. Invert Binary Tree [LeetCode]
- poj 1111 dfs求面积问题
- spring data elasticsearch在集群新建了索引出现unsigned
- Oracle常用字符集
- powershell如何ping
- .htaccess .htpasswd 访问密码设置
- css3 transform
- CS0012: 类型“System.Web.Routing.RouteValueDictionary”在未被引用的程序集中定义。必须添加对程序集“System.Web.Routing, Version