.NET – Unable to set up animation for the ContentControl background color, but you can use foreground

I am trying to animate the selection change of the list box 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}" />

< p>But the next one does not work (System.InvalidOperationException: Unable to resolve TargetProperty(ContentControl.Background).(SolidColorBrush.Color) on the specified object.

For In my life, I can’t find the reason.

You need to explicitly set the Background property on the ContentControl For some content to make the animation take effect.

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 property of null.

It is suitable for Foreground, because the default of value Foreground property is a black brush, so the default setting Is a valid non-null value.

I am trying to animate the selection change of the list box in Windows Phone 8. The following animation is valid:

But the next one does not work (System.InvalidOperationException: Unable to resolve TargetProperty(ContentControl.Background).(SolidColorBrush.Color).

For the life of me, I can’t find the reason.

You need to explicitly set the Background property on the ContentControl to Some content can make the animation take effect.

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 property of null.

It is suitable for Foreground, because the default of value Foreground property is a black brush, so the default is set to a valid non-null value.

< /p>

Leave a Comment

Your email address will not be published.