bbz
bbz

Reputation: 15

Border background color continous animation

I want that my border is continuously changing color from yellow to red. I tried this code, but it doesn't work. Why?

<Border Background="Yellow">
    <Border.Triggers>
        <EventTrigger RoutedEvent="Border.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation Storyboard.TargetProperty="Background.(SolidColorBrush.Color)" From="Yellow" To="Red" Duration="0:0:0.2"
                                            RepeatBehavior="Forever"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Border.Triggers>
</Border>

Upvotes: 0

Views: 332

Answers (1)

Clemens
Clemens

Reputation: 128013

The Yellow SolidColorBrush that is assigned to the Background may not be animatable.

It is safer to declare it like this:

<Border>
    <Border.Background>
        <SolidColorBrush Color="Yellow"/>
    </Border.Background>
    <Border.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <ColorAnimation
                        Storyboard.TargetProperty="Background.Color"
                        From="Yellow" To="Red" Duration="0:0:0.2"
                        AutoReverse="True" RepeatBehavior="Forever"/>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Border.Triggers>
</Border>

Upvotes: 1

Related Questions