我正在尝试为 Windows Phone 8 中列表框的选择更改设置动画。以下动画有效:
<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}" />
对于我的生活,我找不到原因。
最佳答案
您需要明确设置 Background
您的 ContentControl
上某物的属性(property)使动画工作。
你需要这个是因为 default value的Background
属性是 null
所以当动画解析表达式 (ContentControl.Background).(SolidColorBrush.Color)
它无法访问 Color
null
的属性(property).
它适用于 Foreground
因为default of value Foreground
属性是黑色画笔,因此默认设置为有效的非空值。
关于.net - 无法为 ContentControl 背景颜色设置动画,但可以与前景一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16511654/