主框架上有按钮和控件以及堆叠面板。试图将工作动画从xaml移动到.cs我已经编写了下一个很酷的函数)):
private void ToggleButton_Checked(object sender, RoutedEventArgs e)
{
int heightBottom = 100;
System.Windows.Thickness th = stackPanel1.Margin;
th.Top = stackPanel1.Margin.Top + heightBottom;
ThicknessAnimation animStackPanel1 = new ThicknessAnimation
{
From = stackPanel1.Margin,
To = th,
AccelerationRatio = 0.2,
FillBehavior = FillBehavior.Stop,
DecelerationRatio = 0.8,
Duration = DURATION
};
System.Windows.Thickness th2 = fxPSEditorView.Margin;
th2.Right = fxPSEditorView.Margin.Right - heightBottom;
th2.Bottom = fxPSEditorView.Margin.Bottom - heightBottom;
ThicknessAnimation animPSEditorView = new ThicknessAnimation
{
From = fxPSEditorView.Margin,
To = th2,
AccelerationRatio = 0.2,
FillBehavior = FillBehavior.Stop,
DecelerationRatio = 0.8,
Duration = DURATION
};
Storyboard.SetTarget(animPSEditorView, fxPSEditorView);
Storyboard.SetTargetProperty(fxPSEditorView, new PropertyPath(MarginProperty));
sb.Children.Add(animPSEditorView);
Storyboard.SetTarget(animStackPanel1, stackPanel1);
Storyboard.SetTargetProperty(stackPanel1, new PropertyPath(MarginProperty));
sb.Children.Add(animStackPanel1);
sb.Begin();//null reference error here!
};
据我所知,我必须为sb.Begin指定两个参数 - 一个用于stackPanel1,另一个用于fxPSEditorView。但它不需要一组对象作为第一个参数。 如何运行这个动画的任何想法将是好的!谢谢