厚度动画麻烦?(带有Begin函数参数)
本文关键字:Begin 函数 参数 带有 动画 麻烦 | 更新日期: 2023-09-27 18:18:02
有一个主框架,上面有一个按钮和控件,还有stackpanel。试图将工作动画从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。但是它不把一组对象作为第一个参数。任何想法如何运行这个动画将是受欢迎的!谢谢你
您不需要两个参数,但您应该传递包含正在动画的控件的控件(它们需要在相同的name-scope中)。阅读Begin(FrameworkElement)
的文档