管理控件状态和管理控件状态的转换逻辑

<Window.Resources>
<Style TargetType="Button" x:Key="AnimatedStyle" >
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<!-- Define our button's border. Note that
the text color is inherited by child
elements, that is we give it a name, so
we can target it with the animation -->
<Border BorderBrush="Black" BorderThickness="1"
CornerRadius="2"
TextBlock.Foreground="WhiteSmoke"
Name="theBorder">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions> <!-- To match the appearance of a typical button,
we use two rectangles -->
<Rectangle Name="topBackground" Fill="DarkGray"/>
<Rectangle Grid.Row="1" Name="bottomBackground"
Fill="Black" /> <!-- The content presenter shows the
button's text -->
<ContentPresenter Grid.RowSpan="2"
VerticalAlignment="Center"
HorizontalAlignment="Center" />
</Grid>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates"> <!-- Here is where we define
the disable animation -->
<!--控件有状态:Disabled,Normal等等-->
<VisualState Name="Disabled">
<Storyboard>
<ColorAnimation
Storyboard.TargetName="topBackground"
Storyboard.TargetProperty="(Rectangle.Fill).(Color)"
To="White" Duration="0:0:.5" />
<ColorAnimation
Storyboard.TargetName="bottomBackground"
Storyboard.TargetProperty="(Rectangle.Fill).(Color)"
To="WhiteSmoke" Duration="0:0:0.5" />
<ColorAnimation
Storyboard.TargetName="theBorder"
Storyboard.TargetProperty="(TextBlock.Foreground).(Color)"
To="Gray" Duration="0:0:0.5" />
</Storyboard>
</VisualState> <!-- Here is where the enabled animation
is defined -->
<VisualState Name="Normal">
<Storyboard>
<ColorAnimation
Storyboard.TargetName="topBackground"
Storyboard.TargetProperty="(Rectangle.Fill).Color"
To="DarkGray" Duration="0:0:0.5" />
<ColorAnimation
Storyboard.TargetName="bottomBackground"
Storyboard.TargetProperty="(Rectangle.Fill).(Color)"
To="Black" Duration="0:0:0.5" />
<ColorAnimation
Storyboard.TargetName="theBorder"
Storyboard.TargetProperty="(TextBlock.Foreground).Color"
To="WhiteSmoke" Duration="0:0:0.5" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<CheckBox Grid.Row="0" Content="Enable Button"
Name="chkEnabled" IsChecked="True" VerticalAlignment="Center" />
<!--此处通过IsEnabled来进行Disabled,Normal二者的切换-->
<Button Grid.Row="1" Content="Test Button" Name="btnTest"
IsEnabled="{Binding ElementName=chkEnabled,Path=IsChecked}"
Style="{StaticResource AnimatedStyle}" Click="ButtonClick"/>
</Grid>

示例代码

https://github.com/zLulus/NotePractice/tree/dev3/WPF/WpfDemo/VisualStateManager

VisualStateManager的更多相关文章

  1. 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI

    [源码下载] 背水一战 Windows 10 (7) - 控件 UI: VisualState, VisualStateManager, 控件的默认 UI 作者:webabcd 介绍背水一战 Wind ...

  2. 控件 UI: VisualState, VisualStateManager, 控件的默认 UI

    VisualState 和 VisualStateManager 控件的默认 Style, ControlTemplate, VisualState 示例1.演示“VisualState 和 Visu ...

  3. 重新想象 Windows 8 Store Apps (15) - 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState, VisualStateManager

    原文:重新想象 Windows 8 Store Apps (15) - 控件 UI: 字体继承, Style, ControlTemplate, SystemResource, VisualState ...

  4. WPF: WPF 中的 Triggers 和 VisualStateManager

    在之前写的这篇文章 WPF: 只读依赖属性的介绍与实践 中,我们介绍了在 WPF 自定义控件中如何添加只读依赖属性,并且使其结合属性触发器 (Trigger) 来实现对控件样式的改变.事实上,关于触发 ...

  5. 在编写wpf界面时候中出现如下错误: 类型引用不明确。至少有两个名称空间(“System.Windows”和“System.Windows”)中已出现名为“VisualStateManager”的类型。请考虑调整程序集 XmlnsDefinition 特性。

    wpf中类型引用不明确.至少有两个名称空间(“System.Windows”和“System.Windows”)中已出现名为“VisualState 你是不是用了WPFToolKit?如果是的,那原因 ...

  6. 【WIN10】VisualStateManager使用說明

    Demo下載:http://yunpan.cn/cFjgPtWRHKH9H  访问密码 c4b7 顧名思義,視圖狀態管理器. 在WPF中,它的功能似乎更強大.在UWP中,閹割了GotElementSt ...

  7. WPF CheckBox 样式

    <Style x:Key="FocusVisual"> <Setter Property="Control.Template"> < ...

  8. WinRT自定义控件第一 - 转盘按钮控件

    之前的文章中,介绍了用WPF做一个转盘按钮控件,后来需要把这个控件移植到WinRT时,遇到了很大的问题,主要原因在于WPF和WinRT还是有很大不同的.这篇文章介绍了这个移植过程,由于2次实现的控件功 ...

  9. WPF自定义控件第二 - 转盘按钮控件

    继之前那个控件,又做了一个原理差不多的控件.这个控件主要模仿百度贴吧WP版帖子浏览界面左下角那个弹出的按钮盘.希望对大家有帮助. 这个控件和之前的也差不多,为了不让大家白看,文章最后发干货. 由于这个 ...

随机推荐

  1. ios开发网络学习五:MiMEType ,多线程下载文件思路,文件的压缩和解压缩

    一:MiMEType:一般可以再百度上搜索到相应文件的MiMEType,或是利用c语言的api去获取文件的MiMEType : //对该文件发送一个异步请求,拿到文件的MIMEType - (void ...

  2. JS学习十四天----server端运行JS代码

    server端运行JS代码 话说,当今不在client使用JS代码才是稀罕事.因为web应用的体验越来越丰富,client用JS实现的逻辑也越来越多,这造成的结果就是某些差点儿一致的逻辑须要在clie ...

  3. C#中使用split分割字符串的几种方法小结

    1.用字符串分隔: using System.Text.RegularExpressions;string str="aaajsbbbjsccc";string[] sArray= ...

  4. C++ 中的 const 类型变量

    之前总感觉C/C++中有const 限定的变量是个很头痛的问题,一会儿能够变.一会儿不能够变,一会儿把const赋给nonconst,一会儿又把nonconst赋给const,头都被它搞大了.今天刚好 ...

  5. 线程基础:JDK1.5+(9)——线程新特性(中)

    (接上文<线程基础:JDK1.5+(8)--线程新特性(上)>) 3.工作在多线程环境下的"计数器": 从这个小节開始,我们将以一个"赛跑"的样例. ...

  6. iOS app审核参考信息地址

    发件人:(苹果开发支持邮箱地址) 中国区电话:400-670-1855 chinadev<chinadev@asia.apple.com>   您好: 感谢您与 Apple 开发者计划支持 ...

  7. iOS8.1 编译ffmpeg和集成第三方实现直播(监控类)

    iOS8.1 编译ffmpeg和集成第三方实现直播(监控类) http://www.mamicode.com/info-detail-476094.html 一,下载并在终端中运行脚本编译ffmpeg ...

  8. KeePass v1.30

    Changes from 1.29 to 1.30: New Features:Refined application icons (thanks to Victor Andreyenkov).Add ...

  9. 一个封装了的选项卡效果js

    转载自:http://www.cnblogs.com/skyblue/archive/2008/04/26/1171968.html <!DOCTYPE HTML PUBLIC "-/ ...

  10. Servlet接口的实现类,路径配置映射,ServletConfig对象,ServletContext对象及web工程中文件的读取

    一,Servlet接口实现类:sun公司为Servlet接口定义了两个默认的实现类,分别为:GenericServlet和HttpServlet. HttpServlet:指能够处理HTTP请求的se ...