Controlling The Storyboard : Storyboard « Windows Presentation Foundation « C# / C Sharp






Controlling The Storyboard

Controlling The Storyboard
      
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel>
        <Canvas Width="350" Height="200">
            <Rectangle Canvas.Left="150" Canvas.Top="50" Fill="Aqua" Width="50" Height="150">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <RotateTransform x:Name="xform1" Angle="-90" CenterX="0" CenterY="150" />
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>
        </Canvas>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
            <Button Name="btnBegin" Content="Begin" />
            <Button Name="btnPause" Content="Pause" />
            <Button Name="btnResume" Content="Resume" />
            <Button Name="btnStop" Content="Stop" />
            <Button Name="btnSkip" Content="Skip to End" />
            <Button Name="btnCenter" Content="Skip to Center" />
        </StackPanel>

        <StackPanel.Triggers>
            <EventTrigger SourceName="btnBegin" RoutedEvent="Button.Click">
                <BeginStoryboard Name="storybrd">
                    <Storyboard >
                        <DoubleAnimation 
                            Storyboard.TargetName="xform1"
                            Storyboard.TargetProperty="Angle"
                            From="-90" To="0" Duration="0:0:5" />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>

            <EventTrigger SourceName="btnPause" RoutedEvent="Button.Click">
                <PauseStoryboard BeginStoryboardName="storybrd" />
            </EventTrigger>

            <EventTrigger SourceName="btnResume" RoutedEvent="Button.Click">
                <ResumeStoryboard BeginStoryboardName="storybrd" />
            </EventTrigger>

            <EventTrigger SourceName="btnStop" RoutedEvent="Button.Click">
                <StopStoryboard BeginStoryboardName="storybrd" />
            </EventTrigger>

            <EventTrigger SourceName="btnSkip" RoutedEvent="Button.Click">
                <SkipStoryboardToFill BeginStoryboardName="storybrd" />
            </EventTrigger>

            <EventTrigger SourceName="btnCenter" RoutedEvent="Button.Click">
                <SeekStoryboard BeginStoryboardName="storybrd"
                                Offset="0:0:5" />
            </EventTrigger>

        </StackPanel.Triggers>
    </StackPanel>
</Page>

   
    
    
    
    
    
  








Related examples in the same category

1.EventTrigger RoutedEvent=Image.LoadedEventTrigger RoutedEvent=Image.Loaded
2.Trigger Animation by Mouse in out actionTrigger Animation by Mouse in out action
3.Remove Animations with StoryboardRemove Animations with Storyboard
4.Create an interactive animation using XAML and the StoryboardCreate an interactive animation using XAML and the Storyboard
5.Create animations using the Storyboard in codeCreate animations using the Storyboard in code
6.Get resource in code as StoryboardGet resource in code as Storyboard
7.Stop, resume animation with StoryboardStop, resume animation with Storyboard