| 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Diagnostics; |
| 4 | using System.Text; |
| 5 | using System.Windows; |
| 6 | using System.Windows.Controls; |
| 7 | using System.Windows.Media; |
| 8 | using System.Windows.Media.Animation; |
| 9 | |
| 10 | namespace UI.Controls.Base |
| 11 | { |
| 12 | public class Placeholder : Control |
| 13 | { |
| 14 | public CornerRadius CornerRadius |
| 15 | { |
| 16 | get { return (CornerRadius)GetValue(CornerRadiusProperty); } |
| 17 | set { SetValue(CornerRadiusProperty, value); } |
| 18 | } |
| 19 | public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", |
| 20 | typeof(CornerRadius), |
| 21 | typeof(Placeholder)); |
| 22 | |
| 23 | private Border Flash; |
| 24 | private bool IsAddEvent = false; |
| 25 | public Placeholder() |
| 26 | { |
| 27 | DefaultStyleKey = typeof(Placeholder); |
| 28 | } |
| 29 | |
| 30 | |
| 31 | |
| 32 | public override void OnApplyTemplate() |
| 33 | { |
| 34 | base.OnApplyTemplate(); |
| 35 | Flash = GetTemplateChild("Flash") as Border; |
| 36 | if (!IsAddEvent) |
| 37 | { |
| 38 | Loaded += Placeholder_Loaded; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | private void Placeholder_Loaded(object sender, RoutedEventArgs e) |
| 43 | { |
| 44 | Loaded -= Placeholder_Loaded; |
| 45 | |
| 46 | Animation(); |
| 47 | } |
| 48 | |
| 49 | private void Animation() |
| 50 | { |
| 51 | Storyboard storyboard = new Storyboard(); |
| 52 | DoubleAnimation scrollAnimation = new DoubleAnimation(); |
| 53 | scrollAnimation.From = -10; |
| 54 | scrollAnimation.To = ActualWidth; |
| 55 | |
| 56 | scrollAnimation.EasingFunction = new SineEase() { EasingMode = EasingMode.EaseIn }; |
| 57 | Storyboard.SetTarget(scrollAnimation, Flash); |
| 58 | Storyboard.SetTargetProperty(scrollAnimation, new PropertyPath("RenderTransform.Children[0].X")); |
| 59 | scrollAnimation.AutoReverse = true; |
| 60 | scrollAnimation.RepeatBehavior = RepeatBehavior.Forever; |
| 61 | scrollAnimation.Duration = new Duration(TimeSpan.FromSeconds(1)); |
| 62 | |
| 63 | storyboard.Children.Add(scrollAnimation); |
| 64 | |
| 65 | storyboard.Begin(); |
| 66 | |
| 67 | IsAddEvent = true; |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | } |