我是以编程方式在依赖项属性上启动DoubleAnimation(显然是double)。这是代码的截断版本:
// Using a DependencyProperty as the backing store for TestDoubleValue. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TestDoubleValueProperty =
DependencyProperty.Register("TestDoubleValue", typeof(double), typeof(MainWindow), new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsArrange));
void BeginAnimation()
{
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation(0, 100, new Duration(TimeSpan.FromMilliseconds(1000)));
Storyboard.SetTarget(da, this);
Storyboard.SetTargetProperty(da, new PropertyPath(TestDoubleValueProperty));
sb.Children.Add(da);
sb.FillBehavior = FillBehavior.Stop;
sb.Begin();
SetValue(TestDoubleValueProperty, 100.0);
}
但是,我想要实现的行为是:
我目前看到的行为如下:
100, 0, 0.52647, 0.92353, ...
我如何实现这种行为?
我目前的想法是,我会做这样的事情:
SetValue(TestDoubleValueProperty, 100.0);
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation(0, 100, new Duration(TimeSpan.FromMilliseconds(1000)));
Storyboard.SetTarget(da, this);
Storyboard.SetTargetProperty(da, new PropertyPath(TestDoubleValueProperty));
sb.Children.Add(da);
sb.Completed += (s, arg) => { sb.Remove(); };
sb.Begin();
SetCurrentValue(TestDoubleValueProperty, 0.0);
这似乎有效,但似乎有点hacky。还有更好的方法吗?