Simple Animation In WPF

Posted by Abhisek under WPF category on | Views : 3514
<Window x:Class="MyWPFApp.Window1"
Title="Simple Animation" Height="192" Width="428">

<!-- Do everything in a stack panel-->
<StackPanel Margin="20">

<!-- Create a rectangle to which will be animated -->
<Rectangle Name="SimpleGreenRectangle"
Fill="Firebrick" Width="50" Height="26">
<OuterGlowBitmapEffect GlowColor="DarkViolet" />
<!-- Create a second stack panel to hold
buttons to start and stop the animations -->
<StackPanel Orientation="Vertical" Margin="0,20,0,0">
<Button Name="btnStart" Width="133">
<DropShadowBitmapEffect Color="Chartreuse" />
</Button.BitmapEffect> Start</Button>
<Button Name="btnStop" Width="132">
<DropShadowBitmapEffect Color="Chartreuse" />
</Button.BitmapEffect> Stop</Button>

<!-- Associating the clicking of each button
with a stack of XAML that starts or stops the animation -->
<EventTrigger SourceName="btnStart" RoutedEvent="Button.Click">
<BeginStoryboard Name="myStoryboard">
<!-- Create an animation that repeats indefinetly. -->
From="50" To="300" Duration="0:0:4" RepeatBehavior="Forever" />
<EventTrigger SourceName="btnStop" RoutedEvent="Button.Click">
<StopStoryboard BeginStoryboardName="myStoryboard" />


Comment InitializeComponent(); in the .cs file.

Comments or Responses

Login to post response