diff MetroWpf/MetroWpf.Xaml/Transitions/Fade.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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MetroWpf/MetroWpf.Xaml/Transitions/Fade.cs	Tue Mar 20 20:18:35 2012 +0000
@@ -0,0 +1,39 @@
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media.Animation;
+
+namespace MetroWpf.Xaml.Transitions
+{
+    // Simple transition that fades out the old content
+    public class FadeTransition : Transition
+    {
+        static FadeTransition()
+        {
+            IsNewContentTopmostProperty.OverrideMetadata(typeof(FadeTransition), new FrameworkPropertyMetadata(false));
+        }
+
+        public Duration Duration
+        {
+            get { return (Duration)GetValue(DurationProperty); }
+            set { SetValue(DurationProperty, value); }
+        }
+
+        public static readonly DependencyProperty DurationProperty =
+            DependencyProperty.Register("Duration", typeof(Duration), typeof(FadeTransition), new UIPropertyMetadata(Duration.Automatic));
+
+        protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
+        {
+            DoubleAnimation da = new DoubleAnimation(0, Duration);
+            da.Completed += delegate
+            {
+                EndTransition(transitionElement, oldContent, newContent);
+            };
+            oldContent.BeginAnimation(UIElement.OpacityProperty, da);
+        }
+
+        protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent)
+        {
+            oldContent.BeginAnimation(UIElement.OpacityProperty, null);
+        }
+    }
+}