annotate MetroWpf/MetroWpf.Xaml/Transitions/StoryboardTransition.cs @ 24:a8b50a087544

Stocks and FxRates working, new menu introduced. Working nicely so far
author adminsh@apollo
date Tue, 20 Mar 2012 20:18:35 +0000
parents
children
rev   line source
24
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
1 using System.Windows;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
2 using System.Windows.Controls;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
3 using System.Windows.Media.Animation;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
4
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
5 namespace MetroWpf.Xaml.Transitions
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
6 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
7 // Transition with storyboards for the old and new content presenters
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
8 [StyleTypedProperty(Property = "OldContentStyle", StyleTargetType = typeof(ContentPresenter))]
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
9 [StyleTypedProperty(Property = "NewContentStyle", StyleTargetType = typeof(ContentPresenter))]
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
10 public class StoryboardTransition : Transition
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
11 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
12 public Style OldContentStyle
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
13 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
14 get { return (Style)GetValue(OldContentStyleProperty); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
15 set { SetValue(OldContentStyleProperty, value); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
16 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
17
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
18 public static readonly DependencyProperty OldContentStyleProperty =
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
19 DependencyProperty.Register("OldContentStyle",
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
20 typeof(Style),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
21 typeof(StoryboardTransition),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
22 new UIPropertyMetadata(null));
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
23
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
24 public Storyboard OldContentStoryboard
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
25 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
26 get { return (Storyboard)GetValue(OldContentStoryboardProperty); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
27 set { SetValue(OldContentStoryboardProperty, value); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
28 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
29
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
30 public static readonly DependencyProperty OldContentStoryboardProperty =
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
31 DependencyProperty.Register("OldContentStoryboard",
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
32 typeof(Storyboard),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
33 typeof(StoryboardTransition),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
34 new UIPropertyMetadata(null));
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
35
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
36 public Style NewContentStyle
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
37 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
38 get { return (Style)GetValue(NewContentStyleProperty); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
39 set { SetValue(NewContentStyleProperty, value); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
40 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
41
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
42 public static readonly DependencyProperty NewContentStyleProperty =
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
43 DependencyProperty.Register("NewContentStyle",
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
44 typeof(Style),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
45 typeof(StoryboardTransition),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
46 new UIPropertyMetadata(null));
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
47
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
48 public Storyboard NewContentStoryboard
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
49 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
50 get { return (Storyboard)GetValue(NewContentStoryboardProperty); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
51 set { SetValue(NewContentStoryboardProperty, value); }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
52 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
53
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
54 public static readonly DependencyProperty NewContentStoryboardProperty =
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
55 DependencyProperty.Register("NewContentStoryboard",
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
56 typeof(Storyboard),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
57 typeof(StoryboardTransition),
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
58 new UIPropertyMetadata(null));
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
59
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
60 protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
61 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
62 Storyboard oldStoryboard = OldContentStoryboard;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
63 Storyboard newStoryboard = NewContentStoryboard;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
64
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
65 if (oldStoryboard != null || newStoryboard != null)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
66 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
67 oldContent.Style = OldContentStyle;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
68 newContent.Style = NewContentStyle;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
69
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
70 // Flag to determine when both storyboards are done
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
71 bool done = oldStoryboard == null || newStoryboard == null;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
72
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
73 if (oldStoryboard != null)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
74 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
75 oldStoryboard = oldStoryboard.Clone();
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
76 oldContent.SetValue(OldContentStoryboardProperty, oldStoryboard);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
77 oldStoryboard.Completed += delegate
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
78 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
79 if (done)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
80 EndTransition(transitionElement, oldContent, newContent);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
81 done = true;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
82 };
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
83 oldStoryboard.Begin(oldContent, true);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
84 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
85
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
86 if (newStoryboard != null)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
87 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
88 newStoryboard = newStoryboard.Clone();
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
89 newContent.SetValue(NewContentStoryboardProperty, newStoryboard);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
90 newStoryboard.Completed += delegate
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
91 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
92 if (done)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
93 EndTransition(transitionElement, oldContent, newContent);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
94 done = true;
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
95 };
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
96 newStoryboard.Begin(newContent, true);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
97 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
98 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
99 else
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
100 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
101 EndTransition(transitionElement, oldContent, newContent);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
102 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
103 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
104
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
105 protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
106 {
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
107 Storyboard oldStoryboard = (Storyboard)oldContent.GetValue(OldContentStoryboardProperty);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
108 if (oldStoryboard != null)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
109 oldStoryboard.Stop(oldContent);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
110 oldContent.ClearValue(ContentPresenter.StyleProperty);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
111
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
112 Storyboard newStoryboard = (Storyboard)newContent.GetValue(NewContentStoryboardProperty);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
113 if (newStoryboard != null)
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
114 newStoryboard.Stop(newContent);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
115 newContent.ClearValue(ContentPresenter.StyleProperty);
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
116 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
117 }
a8b50a087544 Stocks and FxRates working, new menu introduced. Working nicely so far
adminsh@apollo
parents:
diff changeset
118 }