Cannot change background color of ContentControl, but works with Foreground

I am trying to animate a change in Listbox selection in Windows Phone 8. The following animation Works:

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

But the following does not work (System.InvalidOperationException: Cannot resolve TargetProperty (ContentControl.Background). (SolidColorBrush.Color) for the specified object.

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

In life, I can’t understand the reason.

+4
source share
1 answer

You need to explicitly set the Background property to something on your ContentControl for the animation to work.

You need this because the default value of the Background property is null , so when the animation parses the expression (ContentControl.Background).(SolidColorBrush.Color) , it cannot access the Color null property.

And it works with Foreground , because the default value of the Foreground property is a black brush, so it is set to a valid value other than zero.

+6
source

Source: https://habr.com/ru/post/1480369/


All Articles