WPF--Blend制作Button控件模板--问题补充
2013-10-23 12:09
295 查看
补充记录Button控件模板
控件模板制作过程中出现下图问题:动画对象不能用于动画属性"Fill”
并且这类问题Blend4中包括VS2010中仍然可以运行,但是只有VS2010中会报错;如下图
模板代码为如下:
引用上述Button模板就会发生VS2010报错,但是运行时没有问题的。
经过反复的尝试,最终发现原来是如下图这段代码导致:
原本这是用于显示模板Normal下的的动画,导致VS2010报错。原本的报错内容在网上也没有找到答案。
最终代码改成了如下:
去掉模板Normal下的动画内容,VS2010就不会报错。
控件模板制作过程中出现下图问题:动画对象不能用于动画属性"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就不会报错。
相关文章推荐
- 信任
- php版本不同导致报错:Deprecated: Function eregi() is deprecated in
- 视频分享:做“有料”的计算机大学生
- 视频分享:做“有料”的计算机大学生
- ORACLE存储过程和包管理(导出包内容,查询用到了哪些表等)
- lua中赋值nil操作
- LDAP查询实例
- rmdir命令
- 使用Dom4j解析XML
- JS数组方法汇总 array数组元素的添加和删除
- [BTS] Error biztalk arguments null exception string reference not set to an instance of a string. parameter name
- c++获取字符串长度的方法
- rm命令
- 黑客的真正意义
- 狼图腾宣言
- 程序员老鸟写sql语句的经验之谈
- mfc中socket字符接收不完整unicode问题
- stm32f4 DAC DMA 频率发生器+FreeRTOS
- Java JFileChooser 使用方法
- 大数相乘的算法实现