Mercurial > silverbladetech
comparison MetroWpf/MetroWpf.Xaml/Transitions/TranslateTransition.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; | |
4 using System.Windows.Media.Animation; | |
5 | |
6 namespace MetroWpf.Xaml.Transitions | |
7 { | |
8 // Applies a Translation to the content. You can specify the starting point of the new | |
9 // content or the ending point of the old content using relative coordinates. | |
10 // Set start point to (-1,0) to have the content slide from the left | |
11 public class TranslateTransition : Transition | |
12 { | |
13 static TranslateTransition() | |
14 { | |
15 ClipToBoundsProperty.OverrideMetadata(typeof(TranslateTransition), new FrameworkPropertyMetadata(true)); | |
16 } | |
17 | |
18 public Duration Duration | |
19 { | |
20 get { return (Duration)GetValue(DurationProperty); } | |
21 set { SetValue(DurationProperty, value); } | |
22 } | |
23 | |
24 public static readonly DependencyProperty DurationProperty = | |
25 DependencyProperty.Register("Duration", typeof(Duration), typeof(TranslateTransition), new UIPropertyMetadata(Duration.Automatic)); | |
26 | |
27 public Point StartPoint | |
28 { | |
29 get { return (Point)GetValue(StartPointProperty); } | |
30 set { SetValue(StartPointProperty, value); } | |
31 } | |
32 | |
33 public static readonly DependencyProperty StartPointProperty = | |
34 DependencyProperty.Register("StartPoint", typeof(Point), typeof(TranslateTransition), new UIPropertyMetadata(new Point())); | |
35 | |
36 public Point EndPoint | |
37 { | |
38 get { return (Point)GetValue(EndPointProperty); } | |
39 set { SetValue(EndPointProperty, value); } | |
40 } | |
41 | |
42 public static readonly DependencyProperty EndPointProperty = | |
43 DependencyProperty.Register("EndPoint", typeof(Point), typeof(TranslateTransition), new UIPropertyMetadata(new Point())); | |
44 | |
45 protected internal override void BeginTransition(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent) | |
46 { | |
47 TranslateTransform tt = new TranslateTransform(StartPoint.X * transitionElement.ActualWidth, StartPoint.Y * transitionElement.ActualHeight); | |
48 | |
49 if (IsNewContentTopmost) | |
50 newContent.RenderTransform = tt; | |
51 else | |
52 oldContent.RenderTransform = tt; | |
53 | |
54 DoubleAnimation da = new DoubleAnimation(EndPoint.X * transitionElement.ActualWidth, Duration); | |
55 tt.BeginAnimation(TranslateTransform.XProperty, da); | |
56 | |
57 da.To = EndPoint.Y * transitionElement.ActualHeight; | |
58 da.Completed += delegate | |
59 { | |
60 EndTransition(transitionElement, oldContent, newContent); | |
61 }; | |
62 tt.BeginAnimation(TranslateTransform.YProperty, da); | |
63 } | |
64 | |
65 protected override void OnTransitionEnded(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent) | |
66 { | |
67 newContent.ClearValue(ContentPresenter.RenderTransformProperty); | |
68 oldContent.ClearValue(ContentPresenter.RenderTransformProperty); | |
69 } | |
70 } | |
71 } |