Search Chirayu Software Solutions Blog

Monday, August 27, 2012

Color Animation in WPF


CODE:
<Rectangle Name="myrect" Width="350" Height="250">
            <Rectangle.Fill>
                <SolidColorBrush x:Name="brush" Color="Red"/>
            </Rectangle.Fill>
            <Rectangle.Triggers>
                <EventTrigger RoutedEvent="Window.Loaded">
                    <BeginStoryboard>
                        <Storyboard RepeatBehavior="Forever">
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Red" To="Green"
                      Duration="0:0:1" BeginTime="0:0:0"/>
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Green" To="Blue"
                      Duration="0:0:1" BeginTime="0:0:1"/>
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Blue" To="Yellow"
                      Duration="0:0:1" BeginTime="0:0:2"/>
                            <ColorAnimation Storyboard.TargetName="brush"
                      Storyboard.TargetProperty="Color" From="Yellow"
                      To="Red" Duration="0:0:1" BeginTime="0:0:3"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Rectangle.Triggers>
        </Rectangle>



The above code produces the following output:
Post a Comment