Click here to Skip to main content
Click here to Skip to main content

WPF Tutorial - Styles, Triggers & Animation

By , 28 Dec 2010
 
WPFAnimationStyles.zip
WPFAnimationStyles
WPFAnimationStyles.suo
WPFAnimationStyles
bin
Debug
WPFAnimationStyles.exe
WPFAnimationStyles.pdb
WPFAnimationStyles.vshost.exe
WPFAnimationStyles.vshost.exe.manifest
obj
x86
Debug
Animation.baml
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
GenerateResource.read.1.tlog
GenerateResource.write.1.tlog
MainWindow.baml
TempPE
Properties.Resources.Designer.cs.dll
WPFAnimationStyles.exe
WPFAnimationStyles.g.resources
WPFAnimationStyles.pdb
WPFAnimationStyles.Properties.Resources.resources
WPFAnimationStyles_MarkupCompile.cache
WPFAnimationStyles_MarkupCompile.i.cache
Properties
Settings.settings
<Window x:Class="WPFAnimationStyles.Animation"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Animation" Height="300" Width="300">
    <Window.Triggers>
        <EventTrigger RoutedEvent="Loaded">
            <BeginStoryboard>
                <Storyboard RepeatBehavior="Forever" Timeline.DesiredFrameRate="30">
                    <DoubleAnimation Storyboard.TargetProperty="Width" From="300" To="200" AutoReverse="True" Duration="0:0:5" ></DoubleAnimation>
                    <DoubleAnimation Storyboard.TargetProperty="Height" From="300" To="200" AutoReverse="True" Duration="0:0:5"></DoubleAnimation>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Border Background="Red" x:Name="brd">
            <Border.Triggers>
                <EventTrigger RoutedEvent="Loaded">
                    <BeginStoryboard>
                        <Storyboard BeginTime="0:0:0" AutoReverse="True" Duration="0:0:5" FillBehavior="HoldEnd">
                            <ColorAnimation From="Red" To="Blue" RepeatBehavior="Forever" Storyboard.TargetProperty="Background.Color">
                            </ColorAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
                
            </Border.Triggers>
        </Border>

        <Border Background="Violet" 
                Grid.Row="1"
              HorizontalAlignment="Stretch"
              VerticalAlignment="Stretch" >
            <Border.Triggers>
                <EventTrigger RoutedEvent="Border.MouseLeftButtonDown">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames 
                                      Storyboard.TargetName="transformObj"
                                      Storyboard.TargetProperty="X"
                                      Duration="0:0:15">
                                    <SplineDoubleKeyFrame Value="500" KeyTime="0:0:3" KeySpline="0.0,0.1 0.1,0.1" />
                                    <SplineDoubleKeyFrame Value="50" KeyTime="0:0:7" KeySpline="0.0,0.1 0.1,0.1"/>
                                    <SplineDoubleKeyFrame Value="300" KeyTime="0:0:13" KeySpline="0.0,0.1 0.1,0.1"/>
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Border.Triggers>
            <Border.RenderTransform>
                <TranslateTransform x:Name="transformObj" X="0" Y="0" />
            </Border.RenderTransform>
        </Border>

    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of use and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Abhishek Sur
Team Leader
India India
Member
Did you like his post?
 
Oh, lets go a bit further to know him better.
Visit his Website : www.abhisheksur.com to know more about Abhishek.
 
Abhishek also authored a book on .NET 4.5 Features and recommends you to read it, you will learn a lot from it.
http://bit.ly/EXPERTCookBook
 
Basically he is from India, who loves to explore the .NET world. He loves to code and in his leisure you always find him talking about technical stuffs.
 
Presently he is working in WPF, a new foundation to UI development, but mostly he likes to work on architecture and business classes. ASP.NET is one of his strength as well.
Have any problem? Write to him in his Forum.
 
You can also mail him directly to abhi2434@yahoo.com
 
Want a Coder like him for your project?
Drop him a mail to contact@abhisheksur.com
 
Visit His Blog

Dotnet Tricks and Tips



Dont forget to vote or share your comments about his Writing

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 28 Dec 2010
Article Copyright 2010 by Abhishek Sur
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid