Saturday, May 3, 2014

Animation with StoryBoard in WPF

<Window x:Class="WpfApplication1.Window6"
        Title="Window6" Height="300" Width="300">
    <Window.Resources>

        <Storyboard x:Key="rotatebeh"  RepeatBehavior="Forever">
                    <DoubleAnimation Storyboard.TargetProperty="Width" Storyboard.TargetName="Button1"
      From="50" To="100" AutoReverse="True" Duration="0:0:5" ></DoubleAnimation>
                    <DoubleAnimation Storyboard.TargetProperty="Height"  Storyboard.TargetName="Button1"
      From="20" To="30" AutoReverse="True" Duration="0:0:5"></DoubleAnimation>
                </Storyboard>
            
      
    </Window.Resources>
    <Grid>
        
        <Button Content="Start" x:Name="Button1" HorizontalAlignment="Left" Margin="97,72,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
        <Rectangle x:Name="rectangle1" Fill="#FFF4F4F5" HorizontalAlignment="Left" Height="100" Margin="97,161,0,0" Stroke="Black" VerticalAlignment="Top" Width="100"/>
        <Button Content="Stop" x:Name="Button2" HorizontalAlignment="Left" Margin="195,72,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2">
            
        </Button>
        <Button Content="Button" HorizontalAlignment="Left" Margin="35,55,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_3"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="17,199,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_4"/>
        <Button Height="23" Margin="102,95,100,0" Name="button3" VerticalAlignment="Top" Content="Opacity" Click="button3_Click">
            <Button.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetName="button3"
                                             Storyboard.TargetProperty="Opacity"
                                             From="1"
                                             To="0"
                                             Duration="0:0:2"
                                             AutoReverse="True"
                                             RepeatBehavior="3x"/>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Button.Triggers>
        </Button>

    </Grid>
</Window>

No comments:

Post a Comment