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