DoubleAnimation 后 SetValue 方法不起作用
SetValue method doesn't work after DoubleAnimation
我有这个代码:
public partial class MainWindow : Window
{
Storyboard st_common = new Storyboard();
DoubleAnimation anim1 = new DoubleAnimation();
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
anim1.Duration = new Duration(TimeSpan.FromSeconds(5));
anim1.From = 10.0;
anim1.To = 100.0;
st_common.Children.Add(anim1);
Storyboard.SetTargetName(anim1, r1.Name);
Storyboard.SetTargetProperty(anim1, new PropertyPath(Canvas.TopProperty));
st_common.Begin(this);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
r1.SetValue(Canvas.TopProperty, 300.0);
r2.SetValue(Canvas.TopProperty, 300.0);
}
}
为什么 SetValue
方法在动画后对 r1 元素不起作用? (r1 和 r2 是矩形)
情节提要动画仍然保持最后一个动画值的值。这是一个已知的 "feature",并且有三种解决方法...
- 将动画 FillBehavior 设置为 Stop
- 删除故事板
- 删除整个动画。
请参阅 https://msdn.microsoft.com/en-us/library/aa970493%28v=vs.110%29.aspx 了解如何执行这些操作。
我有这个代码:
public partial class MainWindow : Window
{
Storyboard st_common = new Storyboard();
DoubleAnimation anim1 = new DoubleAnimation();
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
anim1.Duration = new Duration(TimeSpan.FromSeconds(5));
anim1.From = 10.0;
anim1.To = 100.0;
st_common.Children.Add(anim1);
Storyboard.SetTargetName(anim1, r1.Name);
Storyboard.SetTargetProperty(anim1, new PropertyPath(Canvas.TopProperty));
st_common.Begin(this);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
r1.SetValue(Canvas.TopProperty, 300.0);
r2.SetValue(Canvas.TopProperty, 300.0);
}
}
为什么 SetValue
方法在动画后对 r1 元素不起作用? (r1 和 r2 是矩形)
情节提要动画仍然保持最后一个动画值的值。这是一个已知的 "feature",并且有三种解决方法...
- 将动画 FillBehavior 设置为 Stop
- 删除故事板
- 删除整个动画。
请参阅 https://msdn.microsoft.com/en-us/library/aa970493%28v=vs.110%29.aspx 了解如何执行这些操作。