.net - 无法为 ContentControl 背景颜色设置动画,但可以与前景一起使用

标签 .net silverlight windows-phone-7 xaml animation

我正在尝试为 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 valueBackground属性是 null所以当动画解析表达式 (ContentControl.Background).(SolidColorBrush.Color)它无法访问 Color null 的属性(property).

它适用于 Foreground因为default of value Foreground属性是黑色画笔,因此默认设置为有效的非空值。

关于.net - 无法为 ContentControl 背景颜色设置动画,但可以与前景一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16511654/

相关文章:

silverlight - SharePoint 2010/IIS 7.5 字节范围请求响应整个文件

multithreading - 线程化多个异步调用

javascript - 是否可以通过 JavaScript 捕获 Silverlight 控件的鼠标事件?

c# - 如何在 Windows Phone 中暂停秒表?

c# - 我可以在 Quartz.NET 中自己持久化触发器吗?

c# - 缓存对象列表

.net - C# 应用程序中的全局键盘捕获

.net - 为什么不在大型项目中使用 EF 生成的类?

c# - Windows 手机 : How to stay in the Current page rather than navigating to another page?

xaml - Win 7 手机中的资源字符串到 Xaml