.net 无法设置ContentControl背景色的动画,但可用于前景
我正在尝试在WindowsPhone8中设置列表框选择更改的动画。以下动画作品:.net 无法设置ContentControl背景色的动画,但可用于前景,.net,silverlight,windows-phone-7,xaml,animation,.net,Silverlight,Windows Phone 7,Xaml,Animation,我正在尝试在WindowsPhone8中设置列表框选择更改的动画。以下动画作品: <ColorAnimation Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Duration="00:00:00.25" From="{StaticResource PhoneForegroundColor}" To="{StaticResource PhoneAccentColor}" /&g
<ColorAnimation Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Duration="00:00:00.25" From="{StaticResource PhoneForegroundColor}" To="{StaticResource PhoneAccentColor}" />
但下一个不起作用(System.InvalidOperationException:无法解析指定对象上的TargetProperty(ContentControl.Background)。(SolidColorBrush.Color)
<ColorAnimation Storyboard.TargetProperty="(ContentControl.Background).(SolidColorBrush.Color)" Duration="00:00:00.25" From="{StaticResource PhoneForegroundColor}" To="{StaticResource PhoneAccentColor}" />
就我而言,我无法找出原因。您需要在
ContentControl
上显式地将Background
属性设置为某物,以使动画正常工作
之所以需要此选项,是因为Background
属性的属性为null
,因此当动画解析表达式(ContentControl.Background)。(SolidColorBrush.Color)
时,它无法访问null
属性的Color
它与
前台
一起工作,因为前台
属性是一个黑色画笔,所以默认情况下它被设置为一个有效的非空值。尝试在ContentControl
上设置一个显式的默认后台
…nemesv:WTF???你是对的。但这是否意味着如果它没有设置值???问题是Background
是null
是默认值,另请参见我的答案。然后问题出在异常上。它应该是一个NullReferenceException,而不是说无法解决属性!我不得不为此投入大约2个小时:(是的,例外信息在这里很容易引起误解。