ColorAnimation cannot be used to animate property Background due to incompatible type

When you try to animate the background color of a border element you get above error.

Here is your storyboard

<Storyboard x:Name=”TimerColorAnimation”>
            <ColorAnimation Storyboard.TargetName=”TimerBorder” Storyboard.TargetProperty=”Background” From=”Green” To=”Yellow” AutoReverse=”True” RepeatBehavior=”Forever”></ColorAnimation>
        </Storyboard>

the issue here is that you can not animate the border background like this instead you have to color animation with key frames.

Here is an example of same

<UserControl x:Class=”AnimationsLight.DigitalClock”
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″
    xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″
    mc:Ignorable=”d”
    d:DesignHeight=”300″ d:DesignWidth=”400″>
    <UserControl.Resources>
        <Style TargetType=”TextBlock”>
            <Setter Property=”FontFamily” Value=”Verdana” />
            <Setter Property=”FontSize” Value=”30″/>
        </Style>
        <Storyboard x:Name=”TimerColorAnimation”>
            <ColorAnimationUsingKeyFrames Storyboard.TargetName=”TimerBorder” Storyboard.TargetProperty=”(Border.Background).(SolidColorBrush.Color)” AutoReverse=”True” RepeatBehavior=”Forever”>
                <EasingColorKeyFrame KeyTime=”00:00:01″ Value=”LightGreen”/>
                <EasingColorKeyFrame KeyTime=”00:00:02″ Value=”Pink”/>
                <EasingColorKeyFrame KeyTime=”00:00:03″ Value=”LightPink”/>
                <EasingColorKeyFrame KeyTime=”00:00:04″ Value=”Gray”/>
                <EasingColorKeyFrame KeyTime=”00:00:05″ Value=”LightGray”/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <Grid x:Name=”LayoutRoot” Background=”White”>
        <Canvas>
            <Border x:Name=”TimerBorder” Width=”200″ Height=”100″ BorderBrush=”#FF000000″ Background=”Green” CornerRadius=”3,3,3,3″>
                <StackPanel Orientation=”Horizontal” VerticalAlignment=”Center” HorizontalAlignment=”Center”>
                    <TextBlock x:Name=”Hr”>00</TextBlock>
                    <TextBlock>:</TextBlock>
                    <TextBlock x:Name=”Min”>00</TextBlock>
                    <TextBlock>:</TextBlock>
                    <TextBlock x:Name=”Sec”>00</TextBlock>
                </StackPanel>
            </Border>
        </Canvas>
    </Grid>
</UserControl>

 

The important part here is the how you set the Storyboard.TargetProperty

see the value is

Storyboard.TargetProperty=”(Border.Background).(SolidColorBrush.Color)”

if you will simply set it to Storyboard.TargetProperty=”Background”  the issue will remain same and you will get below error

ColorAnimationUsingKeyFrames cannot be used to animate property Background due to incompatible type. So change the storyboard TargetProperty to (Border.Background).(SolidColorBrush.Color)”  and it will work.

Advertisements

One thought on “ColorAnimation cannot be used to animate property Background due to incompatible type

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s