You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
using System;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows;
|
|
|
|
namespace MultiTerm.Wpf.Behaviours;
|
|
|
|
/// <summary>
|
|
/// From https://stackoverflow.com/questions/14485818/how-to-update-a-progress-bar-so-it-increases-smoothly
|
|
/// </summary>
|
|
public class ProgressBarSmoother
|
|
{
|
|
public static double GetSmoothValue(DependencyObject obj)
|
|
{
|
|
return (double)obj.GetValue(SmoothValueProperty);
|
|
}
|
|
|
|
public static void SetSmoothValue(DependencyObject obj, double value)
|
|
{
|
|
obj.SetValue(SmoothValueProperty, value);
|
|
}
|
|
|
|
public static readonly DependencyProperty SmoothValueProperty =
|
|
DependencyProperty.RegisterAttached(
|
|
"SmoothValue",
|
|
typeof(double),
|
|
typeof(ProgressBarSmoother),
|
|
new PropertyMetadata(0.0, Changing));
|
|
|
|
private static void Changing(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
// guard wrong type
|
|
if(d is not ProgressBar progressBar) { return; }
|
|
|
|
var anim = new DoubleAnimation((double)e.OldValue, (double)e.NewValue, new TimeSpan(0, 0, 0, 0, 250));
|
|
progressBar.BeginAnimation(ProgressBar.ValueProperty, anim, HandoffBehavior.Compose);
|
|
}
|
|
}
|
|
|