Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

wpf storyboard death

By: a guest on Feb 28th, 2012  |  syntax: None  |  size: 1.97 KB  |  views: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public partial class MainWindow : Window
  2. {
  3.     Storyboard a = new Storyboard();
  4.     int i;
  5.     public MainWindow()
  6.     {
  7.         InitializeComponent();
  8.         a.Completed += new EventHandler(a_Completed);
  9.         a.Duration = TimeSpan.FromMilliseconds(10);
  10.         a.Begin();
  11.     }
  12.  
  13.     void a_Completed(object sender, EventArgs e)
  14.     {
  15.         textblock.Text = (++i).ToString();
  16.         a.Begin();
  17.     }
  18. }
  19.        
  20. <Window x:Class="Gui.MainWindow" x:Name="control"
  21. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  22. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  23. Title="MainWindow" Height="300" Width="300">
  24. <Canvas>
  25.     <TextBlock Name="textblock"></TextBlock>
  26. </Canvas>
  27.        
  28. public partial class Window1 : Window
  29. {
  30.     Storyboard a = new Storyboard();
  31.     StringAnimationUsingKeyFrames timeline = new StringAnimationUsingKeyFrames();
  32.     DiscreteStringKeyFrame keyframe = new DiscreteStringKeyFrame();
  33.  
  34.     int i;
  35.  
  36.     public Window1()
  37.     {
  38.         InitializeComponent();
  39.  
  40.         //RunTimeline();
  41.         RunStoryboard();
  42.     }
  43.  
  44.     private void RunTimeline()
  45.     {
  46.         timeline.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(TextBlock.Text)"));
  47.         timeline.Completed += timeline_Completed;
  48.         timeline.Duration = new Duration(TimeSpan.FromMilliseconds(10));
  49.         textblock.BeginAnimation(TextBlock.TextProperty, timeline);
  50.     }
  51.  
  52.     private void RunStoryboard()
  53.     {
  54.         timeline.SetValue(Storyboard.TargetPropertyProperty, new PropertyPath("(TextBlock.Text)"));
  55.         a.Children.Add(timeline);
  56.         a.Completed += a_Completed;
  57.         a.Duration = new Duration(TimeSpan.FromMilliseconds(10));
  58.         a.Begin(textblock);
  59.     }
  60.  
  61.     void timeline_Completed(object sender, EventArgs e)
  62.     {
  63.         textblock.Text = (++i).ToString();
  64.         textblock.BeginAnimation(TextBlock.TextProperty, timeline);
  65.     }
  66.  
  67.     void a_Completed(object sender, EventArgs e)
  68.     {
  69.         textblock.Text = (++i).ToString();
  70.         a.Begin(textblock);
  71.     }
  72. }