Quantcast
Channel: Start/Stop WPF animation
Viewing all articles
Browse latest Browse all 4

Start/Stop WPF animation

$
0
0

How can I make my animation not starting when the program starts, but to trigger it when I want with stop and start buttons? Here' s my XAML:

 

1    <Window2    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"4    	x:Class="WpfTest.MainWindow"5    	x:Name="Window"6    	Title="MainWindow"7    	Width="640" Height="480">8    <Window.Resources>9    <Storyboard x:Key="Storyboard1" RepeatBehavior="Forever">10   <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="BlueEllipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">11   <SplineDoubleKeyFrame KeyTime="00:00:01" Value="406"/>12   </DoubleAnimationUsingKeyFrames>13   </Storyboard>14   </Window.Resources>15   <Window.Triggers>16   <EventTrigger RoutedEvent="FrameworkElement.Loaded">17   <BeginStoryboard Storyboard="{StaticResource Storyboard1}"/>18   </EventTrigger>19   </Window.Triggers>20   21   <Grid x:Name="LayoutRoot">22   <Button x:Name="Start" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Content="Start" Click="StartClick"/>23   <Button x:Name="Stop" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Content="Stop" Margin="75,0,0,0" Click="StopClick"/>24   <Ellipse x:Name="BlueEllipse" Fill="#FF132282" HorizontalAlignment="Left" Margin="75,120,0,0" VerticalAlignment="Top" Width="79" Height="79" RenderTransformOrigin="0.5,0.5">25   <Ellipse.RenderTransform>26   <TransformGroup>27   <ScaleTransform/>28   <SkewTransform/>29   <RotateTransform/>30   <TranslateTransform/>31   </TransformGroup>32   </Ellipse.RenderTransform>33   </Ellipse>34   </Grid>35   </Window>

 

Here' s my code:

1    using System;2    using System.Collections.Generic;3    using System.Linq;4    using System.Text;5    using System.Windows;6    using System.Windows.Controls;7    using System.Windows.Data;8    using System.Windows.Documents;9    using System.Windows.Input;10   using System.Windows.Media;11   using System.Windows.Media.Imaging;12   using System.Windows.Shapes;13   14   namespace WpfTest15   {16   /// &lt;summary&gt;17   	/// Interaction logic for MainWindow.xaml18   	/// &lt;/summary&gt;19   public partial class MainWindow : Window20   	{21   public MainWindow()22   		{23   this.InitializeComponent();24   25   // Insert code required on object creation below this point.26   		}27   28   private void StartClick(object sender, System.Windows.RoutedEventArgs e)29   		{30   // TODO: Add event handler implementation here.31   		}32   33   private void StopClick(object sender, System.Windows.RoutedEventArgs e)34   		{35   // TODO: Add event handler implementation here.36   		}37   	}38   }
 

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>