振る舞いが使える!
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)
{
var anim = new DoubleAnimation((double)e.OldValue, (double)e.NewValue, new TimeSpan(0,0,0,0,250));
(d as ProgressBar).BeginAnimation(ProgressBar.ValueProperty, anim, HandoffBehavior.Compose);
}
}
XAML は次のようになります。
<ProgressBar local:ProgressBarSmoother.SmoothValue="{Binding Progress}">
xaml でバインドしているプロパティが変更されるたびProgress
に、ProgressBarSmoother ビヘイビアーのコードが実行され、適切な値でプログレス バーにアニメーションが追加されTo
ますFrom
。