补充记录Button控件模板

控件模板制作过程中出现下图问题:动画对象不能用于动画属性"Fill”

并且这类问题Blend4中包括VS2010中仍然可以运行,但是只有VS2010中会报错;如下图

模板代码为如下:

     <Style x:Key="BtnS2" TargetType="{x:Type Button}">
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type Button}">
                     <Grid>
                         <VisualStateManager.VisualStateGroups>
                             <VisualStateGroup x:Name="CommonStates">
                                 <VisualState x:Name="Normal">
                                     <Storyboard>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="#00000000"/>
                                         </ColorAnimationUsingKeyFrames>
                                     </Storyboard>
                                 </VisualState>
                                 <VisualState x:Name="MouseOver">
                                     <Storyboard>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="#FF9DC23E"/>
                                         </ColorAnimationUsingKeyFrames>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="White"/>
                                         </ColorAnimationUsingKeyFrames>
                                     </Storyboard>
                                 </VisualState>
                                 <VisualState x:Name="Pressed">
                                     <Storyboard>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="#FF659E11"/>
                                         </ColorAnimationUsingKeyFrames>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="White"/>
                                         </ColorAnimationUsingKeyFrames>
                                     </Storyboard>
                                 </VisualState>
                                 <VisualState x:Name="Disabled"/>
                             </VisualStateGroup>
                         </VisualStateManager.VisualStateGroups>
                         <Rectangle x:Name="rectangle" RadiusY="10" RadiusX="10" Stroke="#00000000" Fill="Black"/>
                         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                     </Grid>
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsFocused" Value="True"/>
                         <Trigger Property="IsDefaulted" Value="True"/>
                         <Trigger Property="IsMouseOver" Value="True"/>
                         <Trigger Property="IsPressed" Value="True"/>
                         <Trigger Property="IsEnabled" Value="False"/>
                     </ControlTemplate.Triggers>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>

引用上述Button模板就会发生VS2010报错,但是运行时没有问题的。

经过反复的尝试,最终发现原来是如下图这段代码导致:

原本这是用于显示模板Normal下的的动画,导致VS2010报错。原本的报错内容在网上也没有找到答案。

最终代码改成了如下:

     <Style x:Key="BtnS2" TargetType="{x:Type Button}">
         <Setter Property="Template">
             <Setter.Value>
                 <ControlTemplate TargetType="{x:Type Button}">
                     <Grid>
                         <VisualStateManager.VisualStateGroups>
                             <VisualStateGroup x:Name="CommonStates">
                                 <VisualState x:Name="Normal"/>
                                 <VisualState x:Name="MouseOver">
                                     <Storyboard>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="#FF9DC23E"/>
                                         </ColorAnimationUsingKeyFrames>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="White"/>
                                         </ColorAnimationUsingKeyFrames>
                                     </Storyboard>
                                 </VisualState>
                                 <VisualState x:Name="Pressed">
                                     <Storyboard>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="#FF659E11"/>
                                         </ColorAnimationUsingKeyFrames>
                                         <ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="rectangle">
                                             <EasingColorKeyFrame KeyTime="0" Value="White"/>
                                         </ColorAnimationUsingKeyFrames>
                                     </Storyboard>
                                 </VisualState>
                                 <VisualState x:Name="Disabled"/>
                             </VisualStateGroup>
                         </VisualStateManager.VisualStateGroups>
                         <Rectangle x:Name="rectangle" RadiusY="10" RadiusX="10" Fill="#00000000" Stroke="#00000000"/>
                         <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                     </Grid>
                     <ControlTemplate.Triggers>
                         <Trigger Property="IsFocused" Value="True"/>
                         <Trigger Property="IsDefaulted" Value="True"/>
                         <Trigger Property="IsMouseOver" Value="True"/>
                         <Trigger Property="IsPressed" Value="True"/>
                         <Trigger Property="IsEnabled" Value="False"/>
                     </ControlTemplate.Triggers>
                 </ControlTemplate>
             </Setter.Value>
         </Setter>
     </Style>

去掉模板Normal下的动画内容,VS2010就不会报错。

WPF--Blend制作Button控件模板--问题补充的更多相关文章

  1. WPF--Blend制作Button控件模板

    博客园新人,WPF初学者.不涉及理论知识,直接进入操作. 记录一下使用Blend制作Button控件模板过程中,学到Blend几个知识点: 1.渐变画笔编辑器的Alpha选项可以调控件的透明度.即下图 ...

  2. WPF中的ControlTemplate(控件模板)(转)

    原文地址 http://www.cnblogs.com/zhouyinhui/archive/2007/03/28/690993.html WPF中的ControlTemplate(控件模板)     ...

  3. WPF中的ControlTemplate(控件模板)

    原文:WPF中的ControlTemplate(控件模板) WPF中的ControlTemplate(控件模板)                                             ...

  4. [转]WPF中的ControlTemplate(控件模板)

    WPF中的ControlTemplate(控件模板)                                                                           ...

  5. WPF基础篇之控件模板(ControlTemplate)

    WPF中每一个控件都有一个默认的模板,该模板描述了控件的外观以及外观对外界刺激所做出的反应.我们可以自定义一个模板来替换掉控件的默认模板以便打造个性化的控件. 与Style不同,Style只能改变控件 ...

  6. WPF 中动态改变控件模板

    在某些项目中,可能需要动态的改变控件的模板,例如软件中可以选择不同的主题,在不同的主题下软件界面.控件的样式都会有所不同,这时即可通过改变控件模板的方式实现期望的功能. 基本方法是当用户点击切换主题按 ...

  7. WPF Button控件模板

     <Window x:Class="ControlTemplateDemo.MainWindow"        xmlns="http://schemas.m ...

  8. WPF知识点--自定义Button(ControlTemplate控件模板)

    ControlTemplate是一种控件模板,可以通过它自定义一个模板来替换掉控件的默认模板以便打造个性化的控件. ControlTemplate包含两个重要的属性:VisualTree 该模板的视觉 ...

  9. Blend 2015 教程 (四)控件模板

    前一篇讲述了修改ListBox样式的方法,本篇将修改性别显示区域的样式. 1. 选择ListBox控件,编辑ItemTemplate的当前项,选择CheckBox控件,在美工板导航栏中点击CheckB ...

随机推荐

  1. [分享]运维分享一一阿里云linux系统mysql密码修改脚本

    [分享]运维分享一一阿里云linux系统mysql密码修改脚本       大象吃豆子 级别: 小白 发帖 12 云币 27 加关注 写私信   只看楼主 更多操作楼主  发表于: 2014-09-3 ...

  2. http UserAgent

    string uAgent = Request.ServerVariables["HTTP_USER_AGENT"].ToLower();  //获取客户端浏览器的请求 判断 是什 ...

  3. 7.PHP内核探索:Apache模块介绍

    Apache概述 Apache是目前世界上使用最为广泛的一种Web Server,它以跨平台.高效和稳定而闻名.按照去年官方统计的数据,Apache服务器的装机量占该市场60%以上的份额.尤其是在 X ...

  4. 来到这里,我放弃了多少- UI基础-疯狂猜图,我们都疯狂了-

    小问题也要问 学习最重要的是 自律 我昨天晚上3点睡的, 这两天一点也没睡 0.99*0.99  每天差一点 日积月累就很多了 关键字,在字典里查一下,在类里面查查 瑞详博客下载器 跑步后精神多了,白 ...

  5. 02/07/2106 @ 6:28am (UTC)

    <?php echo pow(2,32); 4294967296 http://www.unixtimestamp.com/index.php 4294967296 Is equivalent ...

  6. 关于jQuery学习

    ≡[..]≡≡[..]≡ 所有的实例都位于document.ready里面--为了防止文档在未完全加载之前就运行函数导致操作失败. $(document).ready(function(){ --- ...

  7. [转]SQLBulkCopy使用

    SQLBulkCopy,用于数据库之间大批量的数据传递.通常用于新,旧数据库之间数据的更新.即使表结构完全不同,也可以通过字段间的对应关系,顺利的将数据导过来. 首先,SQLBulkCopy需要2个连 ...

  8. Python中定义字符串

    字符串可以用''或者""括起来表示.如果字符串本身包含'怎么办?比如我们要表示字符串 I'm OK ,这时,可以用" "括起来表示: "I'm OK& ...

  9. 低功耗蓝牙4.0BLE编程-nrf51822开发(9)

    Android 4.3以后的系统自动支持蓝牙4.0规范的低功耗蓝牙(BLE).在android4.3之前,蓝牙4.0支持是由手机厂家加入支持的,接口各异,导致开发一个支持蓝牙4.0程序支持市面上的手机 ...

  10. struts json登录

    1.struts.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts P ...