PageRenderTime 735ms CodeModel.GetById 118ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 611ms

/MahApps.Metro.Controls/RevealImage.xaml.cs

https://bitbucket.org/aeoth/mahapps.metro/
C# | 71 lines | 59 code | 12 blank | 0 comment | 0 complexity | 299652fad77a360b9609c1279cb1cd8e MD5 | raw file
 1using System;
 2using System.Windows;
 3using System.Windows.Controls;
 4using System.Windows.Input;
 5using System.Windows.Media;
 6using System.Windows.Media.Animation;
 7
 8namespace MahApps.Metro.Controls
 9{
10    public partial class RevealImage
11    {
12        public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(RevealImage), new UIPropertyMetadata(""));
13        public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(RevealImage), new UIPropertyMetadata(null));
14
15        public string Text
16        {
17            get { return (string)GetValue(TextProperty); }
18            set { SetValue(TextProperty, value); }
19        }
20
21        public ImageSource Image
22        {
23            get { return (ImageSource)GetValue(ImageProperty); }
24            set { SetValue(ImageProperty, value); }
25        }
26
27        
28
29        public RevealImage()
30        {
31            InitializeComponent();
32        }
33
34        private static void TypewriteTextblock(string textToAnimate, TextBlock txt, TimeSpan timeSpan)
35        {
36            var story = new Storyboard
37            {
38                FillBehavior = FillBehavior.HoldEnd
39            };
40
41            DiscreteStringKeyFrame discreteStringKeyFrame;
42            var stringAnimationUsingKeyFrames = new StringAnimationUsingKeyFrames
43            {
44                Duration = new Duration(timeSpan)
45            };
46
47            var tmp = string.Empty;
48            foreach (var c in textToAnimate)
49            {
50                discreteStringKeyFrame = new DiscreteStringKeyFrame
51                {
52                    KeyTime = KeyTime.Paced
53                };
54                tmp += c;
55                discreteStringKeyFrame.Value = tmp;
56                stringAnimationUsingKeyFrames.KeyFrames.Add(discreteStringKeyFrame);
57            }
58
59            Storyboard.SetTargetName(stringAnimationUsingKeyFrames, txt.Name);
60            Storyboard.SetTargetProperty(stringAnimationUsingKeyFrames, new PropertyPath(TextBlock.TextProperty));
61            story.Children.Add(stringAnimationUsingKeyFrames);
62            story.Begin(txt);
63        }
64
65        private void GridMouseEnter(object sender, MouseEventArgs e)
66        {
67
68            TypewriteTextblock(Text.ToUpper(), textBlock, TimeSpan.FromSeconds(.25));
69        }
70    }
71}