我有这段代码:
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是矩形)
答案 0 :(得分:0)
故事板动画仍然保持最后一个动画值的值。这是一个已知的"功能",有三种方法...
请参阅https://msdn.microsoft.com/en-us/library/aa970493%28v=vs.110%29.aspx了解如何执行这些操作。