不能动画内容控制的背景颜色,但与前景工作



我正在尝试在Windows Phone 8中设置列表框的选择变化动画。下面的动画作品:

<ColorAnimation Storyboard.TargetProperty="(ContentControl.Foreground).(SolidColorBrush.Color)" Duration="00:00:00.25" From="{StaticResource PhoneForegroundColor}" To="{StaticResource PhoneAccentColor}" />

但下一个不工作(系统。InvalidOperationException:无法解析指定对象上的TargetProperty (ContentControl.Background).(SolidColorBrush.Color) .

<ColorAnimation Storyboard.TargetProperty="(ContentControl.Background).(SolidColorBrush.Color)" Duration="00:00:00.25" From="{StaticResource PhoneForegroundColor}" To="{StaticResource PhoneAccentColor}" />

我怎么也找不出原因。

您需要显式地将Background属性设置为ContentControl上的某些内容以使动画工作

你需要这个,因为Background属性的默认值是null,所以当动画解析表达式(ContentControl.Background).(SolidColorBrush.Color)时,它不能访问nullColor属性。

它与Foreground一起工作,因为Foreground属性的默认值是黑色画笔,所以它被默认设置为一个有效的非空值

最新更新