2013-05-12 83 views
4

我試圖動畫列表框的Windows Phone中的選擇變化的工作8.以下動漫作品:不能動畫ContentControl中的背景顏色但前景

<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}" /> 

對於我的生活,我不能當場原因

+1

試着在你的ContentControl上設置一個明確的默認'背景'... – nemesv 2013-05-12 20:24:18

+0

nemesv:WTF ???你是對的。但是,這是否意味着該財產不存在,如果它沒有設置價值? – 2013-05-12 20:30:14

+0

問題是'背景'是'null'是默認值,請參閱我的答案。 – nemesv 2013-05-12 20:31:41

回答

6

您需要明確地將Background屬性設置爲ContentControl上的某些內容才能使動畫生效。

你需要這個,因爲Background財產default valuenull所以當動畫解析表達式(ContentControl.Background).(SolidColorBrush.Color)它不能訪問nullColor財產。

它與Foreground一起使用,因爲default of valueForeground屬性是黑色筆刷,所以默認情況下它被設置爲有效的非空值。

+1

然後問題出現異常。它應該是一個NullReferenceException,而不是說不能解析屬性的東西!我必須投入大約2小時的時間:( – 2013-05-12 20:34:56

+2

是的,這裏的例外信息很具誤導性。 – nemesv 2013-05-12 20:36:06

+1

啊,魔術弦的樂趣...... – McGarnagle 2014-02-07 02:26:53