-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathSmoothProgressBar.xaml.cs
executable file
·110 lines (95 loc) · 3.73 KB
/
SmoothProgressBar.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// This is the source code of Telegram for Windows Phone v. 3.x.x.
// It is licensed under GNU GPL v. 2 or later.
// You should have received a copy of the license in this archive (see LICENSE).
//
// Copyright Evgeny Nadymov, 2013-present.
//
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Animation;
namespace Telegram.Controls
{
public partial class SmoothProgressBar
{
private bool _useAnimations = true;
public bool UseAnimations
{
get { return _useAnimations; }
set { _useAnimations = value; }
}
public static readonly DependencyProperty CommandTextProperty = DependencyProperty.Register(
"CommandText", typeof (string), typeof (SmoothProgressBar), new PropertyMetadata(default(string)));
public string CommandText
{
get { return (string) GetValue(CommandTextProperty); }
set { SetValue(CommandTextProperty, value); }
}
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof (double), typeof (SmoothProgressBar), new PropertyMetadata(default(double), OnValueChanged));
private Storyboard _previousStoryboard;
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var smoothProgressBar = (SmoothProgressBar) d;
if ((double) e.NewValue > 0.0)
{
smoothProgressBar.Visibility = Visibility.Visible;
}
//smoothProgressBar.Progress.Value = (double)e.NewValue;
//if ((double)e.NewValue <= 0.0 || (double)e.NewValue >= 1.0)
//{
// smoothProgressBar.Visibility = Visibility.Collapsed;
//}
//return;
var newValue = (double)e.NewValue;
if ((double) e.OldValue > 0.0 && newValue == 0.0)
{
newValue = 1.0;
}
var animation = new DoubleAnimation
{
To = newValue,
Duration = new Duration(TimeSpan.FromSeconds(0.2)),
};
if (smoothProgressBar.UseAnimations)
{
Storyboard.SetTarget(animation, smoothProgressBar.Progress);
Storyboard.SetTargetProperty(animation, new PropertyPath(RangeBase.ValueProperty));
var sb = new Storyboard();
sb.Children.Add(animation);
if ((double)e.NewValue <= 0.0 || (double)e.NewValue >= 1.0)
{
sb.Completed += (sender, args) =>
{
smoothProgressBar.Visibility = Visibility.Collapsed;
};
}
if (smoothProgressBar._previousStoryboard != null)
{
smoothProgressBar._previousStoryboard.Stop();
}
smoothProgressBar._previousStoryboard = sb;
sb.Begin();
}
else
{
smoothProgressBar.Value = newValue;
if ((double)e.NewValue <= 0.0 || (double)e.NewValue >= 1.0)
{
smoothProgressBar.Visibility = Visibility.Collapsed;
}
}
}
public double Value
{
get { return (double) GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public SmoothProgressBar()
{
InitializeComponent();
Visibility = Visibility.Collapsed;
}
}
}