ColorAnimation cannot be used to animate property Background due to incompatible type
2011-08-11 22:22
375 查看
今天在编写一个控件的样式的时候,碰到了如下的异常:
ColorAnimation cannot be used to animate property Background due to incompatible type.
这里是报异常处的XAML代码,
它运行时出现了一个异常:ColorAnimation cannot be used to animate property Background due to incompatible type.
这里说的是ColorAnimation 中因为不兼容的类型,不能给背景设置颜色动画。
通过查找资料和尝试发现: 把TargetProperty改为(Border.Background).(SolidColorBrush.Color)可以解决该问题
当然,这里还有第二种解决方案:
PS:
ObjectAnimationUsingKeyFrames 对指定 Duration(持续动画) 内的一组 KeyFrames (关键帧)中的 Object 属性值进行动画处理。用于定义动画关键帧的一个或多个 DiscreteObjectKeyFrame 对象元素。
MSDN上的关于ObjectAnimationUsingKeyFrames 的实例:
下面的示例使用 ObjectAnimationUsingKeyFrames 类对 Rectangle 的 Fill 属性进行动画处理。此动画按如下方式使用两个关键帧:
通过使用 DiscreteObjectKeyFrame,Rectangle 的 Fill 属性会在动画的前两秒之后突然更改为 LinearGradientBrush。
在动画的第三秒之后,Fill 属性会突然更改为另一个 LinearGradientBrush,然后一直保持到动画结束(总共四秒)。
ColorAnimation cannot be used to animate property Background due to incompatible type.
这里是报异常处的XAML代码,
<ColorAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="Background" Duration="0" To="#FF6B6B6B"> <ColorAnimation.EasingFunction <ExponentialEase Exponent="15" EasingMode="EaseOut"/> </ColorAnimation.EasingFunction> </ColorAnimation>
它运行时出现了一个异常:ColorAnimation cannot be used to animate property Background due to incompatible type.
这里说的是ColorAnimation 中因为不兼容的类型,不能给背景设置颜色动画。
通过查找资料和尝试发现: 把TargetProperty改为(Border.Background).(SolidColorBrush.Color)可以解决该问题
<ColorAnimation Storyboard.TargetName="border" Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" Duration="0" To="#FF6B6B6B"> <ColorAnimation.EasingFunction <ExponentialEase Exponent="15" EasingMode="EaseOut"/> </ColorAnimation.EasingFunction> </ColorAnimation>
当然,这里还有第二种解决方案:
<Storyboard> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="border" Storyboard.TargetProperty="Background"> <DiscreteObjectKeyFrame KeyTime="0" Value="Transparent" /> </ObjectAnimationUsingKeyFrames> </Storyboard>
PS:
ObjectAnimationUsingKeyFrames 对指定 Duration(持续动画) 内的一组 KeyFrames (关键帧)中的 Object 属性值进行动画处理。用于定义动画关键帧的一个或多个 DiscreteObjectKeyFrame 对象元素。
MSDN上的关于ObjectAnimationUsingKeyFrames 的实例:
下面的示例使用 ObjectAnimationUsingKeyFrames 类对 Rectangle 的 Fill 属性进行动画处理。此动画按如下方式使用两个关键帧:
通过使用 DiscreteObjectKeyFrame,Rectangle 的 Fill 属性会在动画的前两秒之后突然更改为 LinearGradientBrush。
在动画的第三秒之后,Fill 属性会突然更改为另一个 LinearGradientBrush,然后一直保持到动画结束(总共四秒)。
<Storyboard x:Name="myStoryboard"> <ObjectAnimationUsingKeyFrames Storyboard.TargetName="animatedRectangle" Storyboard.TargetProperty="Fill" Duration="0:0:4" RepeatBehavior="Forever"> <ObjectAnimationUsingKeyFrames.KeyFrames> <DiscreteObjectKeyFrame KeyTime="0:0:2"> <DiscreteObjectKeyFrame.Value> <LinearGradientBrush> <LinearGradientBrush.GradientStops> <GradientStop Color="Yellow" Offset="0.0" /> <GradientStop Color="Orange" Offset="0.5" /> <GradientStop Color="Red" Offset="1.0" /> </LinearGradientBrush.GradientStops> </LinearGradientBrush> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> <DiscreteObjectKeyFrame KeyTime="0:0:3"> <DiscreteObjectKeyFrame.Value> <RadialGradientBrush GradientOrigin="0.75,0.25"> <RadialGradientBrush.GradientStops> <GradientStop Color="White" Offset="0.0" /> <GradientStop Color="MediumBlue" Offset="0.5" /> <GradientStop Color="Black" Offset="1.0" /> </RadialGradientBrush.GradientStops> </RadialGradientBrush> </DiscreteObjectKeyFrame.Value> </DiscreteObjectKeyFrame> </ObjectAnimationUsingKeyFrames.KeyFrames> </ObjectAnimationUsingKeyFrames> </Storyboard>
相关文章推荐
- ColorAnimation cannot be used to animate property Background due to incompatible type
- is present but cannot be translated into a null value due to being declared as a primitive type
- caffe: fuck compile error again : error: a value of type "const float *" cannot be used to initialize an entity of type "float *"
- javax.servlet.jsp cannot be resolved to a type
- java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
- keil(MDK)中出现error: #513: a value of type "int" cannot be assigned to an entity of type "char *",即函数返回值无法赋值给对应变量的错误
- jsp页面中出现“String cannot be resolved to a type”
- Error "The form cannot be rendered. This may be due to a misconfiguration......"的解决方案
- Button cannot be resolved to a type 解决方法
- javax.servlet.jsp.JspException cannot be resolved to a type
- Json解析异常处理方式(JSONException: Value of type java.lang.String cannot be converted to JSONObject)
- [java][43]XXXcannot be resolved to a type
- 【JUnit】@Test 报错,"Test cannot be resolved to a type"
- Eclipse luna 导入web项目出现错误 String cannot be resolved to a type
- javax.servlet.jsp cannot be resolved to a type
- Optional int parameter 'topicId' is present but cannot be translated into a null value due to being
- 安卓代码迁移:ActionBarActivity: cannot be resolved to a type
- maven项目工程报错:cannot be resolved to a type
- [记录]javax.servlet.jsp.PageContext cannot be resolved to a type
- JSONException: Value of type java.lang.String cannot be converted to JSONObject