WPF: Animations in XAML and code-behind

.NET, Technical stuff, WPF
See comments
WPF makes it very easy to define animations, by using timelines, storyboards and dependency properties. Animations can be defined and triggered in XAML, or they can be defined in XAML and triggered in C#, or they can even be fully defined and triggered in C#.
I just published a tutorial explaining the basic concepts of animations in WPF, with examples and a demo (runs in IE, with WPF September CTP (RC1) installed). The article shows 3 different ways to animate an object. Of course, you can also download the source code.
<Page.Triggers>
  <EventTrigger RoutedEvent="TextBlock.MouseDown"
                SourceName="lblHello">
    <EventTrigger.Actions>
      <BeginStoryboard>
        <Storyboard>
          <DoubleAnimation
            Storyboard.TargetName="lblHello"
            Storyboard.TargetProperty="(TextBlock.RenderTransform).(RotateTransform.Angle)"
            From="0"
            To="360"
            Duration="0:0:0.5"
            RepeatBehavior="4x" />
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger.Actions>
  </EventTrigger>
</Page.Triggers>
WPF animation in XAML
Previous entry | Next blog entry

Responses to “WPF: Animations in XAML and code-behind”

  1. Metropolis12 Says:

    I can't get a video to loop. Do I use repeatBehavior for this?

Comments for WPF: Animations in XAML and code-behind