我正在尝试在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)
时,它不能访问null
的Color
属性。
它与Foreground
一起工作,因为Foreground
属性的默认值是黑色画笔,所以它被默认设置为一个有效的非空值