From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- MediaBrowser.UI.Controls/TransitionFrame.cs | 194 ++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 MediaBrowser.UI.Controls/TransitionFrame.cs (limited to 'MediaBrowser.UI.Controls/TransitionFrame.cs') diff --git a/MediaBrowser.UI.Controls/TransitionFrame.cs b/MediaBrowser.UI.Controls/TransitionFrame.cs new file mode 100644 index 0000000000..e6f8325cc8 --- /dev/null +++ b/MediaBrowser.UI.Controls/TransitionFrame.cs @@ -0,0 +1,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 +{ + /// + /// Class TransitionFrame + /// + public class TransitionFrame : Frame + { + /// + /// The _content presenter + /// + private ContentPresenter _contentPresenter = null; + + #region DP TransitionType + + /// + /// Gets or sets the type of the transition. + /// + /// The type of the transition. + 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... + /// + /// The transition type property + /// + public static readonly DependencyProperty TransitionTypeProperty = + DependencyProperty.Register("TransitionType", typeof(TransitionEffect), typeof(TransitionFrame), + new UIPropertyMetadata(new BlindsTransitionEffect())); + + #endregion DP TransitionType + + #region DP Transition Animation + + /// + /// Gets or sets the transition animation. + /// + /// The transition animation. + 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... + /// + /// The transition animation property + /// + public static readonly DependencyProperty TransitionAnimationProperty = + DependencyProperty.Register("TransitionAnimation", typeof(DoubleAnimation), typeof(TransitionFrame), new UIPropertyMetadata(null)); + + #endregion DP Transition Animation + + /// + /// Called when the template generation for the visual tree is created. + /// + 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(); + } + + /// + /// Animates the content. + /// + /// The navigation action. + /// if set to true [check content]. + /// if set to true [is back]. + 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(); + } + + /// + /// Navigates the with transition. + /// + /// The page. + public void NavigateWithTransition(Page page) + { + AnimateContent(() => Navigate(page)); + } + + /// + /// Navigates the with transition. + /// + /// The page. + public void NavigateWithTransition(Uri page) + { + AnimateContent(() => Navigate(page)); + } + + /// + /// Goes the back with transition. + /// + public void GoBackWithTransition() + { + if (CanGoBack) + { + AnimateContent(GoBack, false, true); + } + } + + /// + /// Goes the forward with transition. + /// + public void GoForwardWithTransition() + { + if (CanGoForward) + { + AnimateContent(GoForward, false); + } + } + + /// + /// Reverses the direction. + /// + /// The transition effect. + 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; + } + } + } + } +} -- cgit v1.2.3