1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
|
using Microsoft.Expression.Media.Effects;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace MediaBrowser.UI.Controls
{
/// <summary>
/// Class TransitionFrame
/// </summary>
public class TransitionFrame : Frame
{
/// <summary>
/// The _content presenter
/// </summary>
private ContentPresenter _contentPresenter = null;
#region DP TransitionType
/// <summary>
/// Gets or sets the type of the transition.
/// </summary>
/// <value>The type of the transition.</value>
public TransitionEffect TransitionType
{
get { return (TransitionEffect)GetValue(TransitionTypeProperty); }
set { SetValue(TransitionTypeProperty, value); }
}
// Using a DependencyProperty as the backing store for TransitionType. This enables animation, styling, binding, etc...
/// <summary>
/// The transition type property
/// </summary>
public static readonly DependencyProperty TransitionTypeProperty =
DependencyProperty.Register("TransitionType", typeof(TransitionEffect), typeof(TransitionFrame),
new UIPropertyMetadata(new BlindsTransitionEffect()));
#endregion DP TransitionType
#region DP Transition Animation
/// <summary>
/// Gets or sets the transition animation.
/// </summary>
/// <value>The transition animation.</value>
public DoubleAnimation TransitionAnimation
{
get { return (DoubleAnimation)GetValue(TransitionAnimationProperty); }
set { SetValue(TransitionAnimationProperty, value); }
}
// Using a DependencyProperty as the backing store for TransitionAnimation. This enables animation, styling, binding, etc...
/// <summary>
/// The transition animation property
/// </summary>
public static readonly DependencyProperty TransitionAnimationProperty =
DependencyProperty.Register("TransitionAnimation", typeof(DoubleAnimation), typeof(TransitionFrame), new UIPropertyMetadata(null));
#endregion DP Transition Animation
/// <summary>
/// Called when the template generation for the visual tree is created.
/// </summary>
public override void OnApplyTemplate()
{
// get a reference to the frame's content presenter
// this is the element we will fade in and out
_contentPresenter = GetTemplateChild("PART_FrameCP") as ContentPresenter;
base.OnApplyTemplate();
}
/// <summary>
/// Animates the content.
/// </summary>
/// <param name="navigationAction">The navigation action.</param>
/// <param name="checkContent">if set to <c>true</c> [check content].</param>
/// <param name="isBack">if set to <c>true</c> [is back].</param>
private void AnimateContent(Action navigationAction, bool checkContent = true, bool isBack = false)
{
if (TransitionType == null || (checkContent && Content == null))
{
CommandBindings.Clear();
navigationAction();
CommandBindings.Clear();
return;
}
var oldContentVisual = this as FrameworkElement;
_contentPresenter.IsHitTestVisible = false;
var da = TransitionAnimation.Clone();
da.From = 0;
da.To = 1;
da.FillBehavior = FillBehavior.HoldEnd;
var transitionEffect = TransitionType.Clone() as TransitionEffect;
if (isBack)
{
ReverseDirection(transitionEffect);
}
transitionEffect.OldImage = new VisualBrush(oldContentVisual);
transitionEffect.BeginAnimation(TransitionEffect.ProgressProperty, da);
_contentPresenter.Effect = transitionEffect;
_contentPresenter.IsHitTestVisible = true;
// Remove base class bindings to remote buttons
CommandBindings.Clear();
navigationAction();
CommandBindings.Clear();
}
/// <summary>
/// Navigates the with transition.
/// </summary>
/// <param name="page">The page.</param>
public void NavigateWithTransition(Page page)
{
AnimateContent(() => Navigate(page));
}
/// <summary>
/// Navigates the with transition.
/// </summary>
/// <param name="page">The page.</param>
public void NavigateWithTransition(Uri page)
{
AnimateContent(() => Navigate(page));
}
/// <summary>
/// Goes the back with transition.
/// </summary>
public void GoBackWithTransition()
{
if (CanGoBack)
{
AnimateContent(GoBack, false, true);
}
}
/// <summary>
/// Goes the forward with transition.
/// </summary>
public void GoForwardWithTransition()
{
if (CanGoForward)
{
AnimateContent(GoForward, false);
}
}
/// <summary>
/// Reverses the direction.
/// </summary>
/// <param name="transitionEffect">The transition effect.</param>
private void ReverseDirection(TransitionEffect transitionEffect)
{
var circleRevealTransitionEffect = transitionEffect as CircleRevealTransitionEffect;
if (circleRevealTransitionEffect != null)
{
circleRevealTransitionEffect.Reverse = true;
return;
}
var slideInTransitionEffect = transitionEffect as SlideInTransitionEffect;
if (slideInTransitionEffect != null)
{
if (slideInTransitionEffect.SlideDirection == SlideDirection.RightToLeft)
{
slideInTransitionEffect.SlideDirection = SlideDirection.LeftToRight;
}
return;
}
var wipeTransitionEffect = transitionEffect as WipeTransitionEffect;
if (wipeTransitionEffect != null)
{
if (wipeTransitionEffect.WipeDirection == WipeDirection.RightToLeft)
{
wipeTransitionEffect.WipeDirection = WipeDirection.LeftToRight;
}
}
}
}
}
|