跳到主要内容

github/tai

公开

Tai · Windows 软件与网站使用时长统计。上游 Planshit/Tai 的源码镜像,非灵栈原创;MIT 许可。来源:https://github.com/Planshit/Tai 。本次为手动同步,暂不提供安装包。

浏览文件

Placeholder.cs

71 行 · 2.1 KB历史下载
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Text;
5using System.Windows;
6using System.Windows.Controls;
7using System.Windows.Media;
8using System.Windows.Media.Animation;
9
10namespace 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}