2011-12-15 26 views
0

有其上有一个按钮和控制,并且还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。但是它不会将一组对象作为第一个参数。 任何想法如何运行这个动画将是很好的!谢谢

回答

1

你并不需要两个参数,但你应该通过它包含正在被动画(这需要在相同的名称,范围)的控件。阅读Begin(FrameworkElement)的文档。

+0

我发现自己的错误:这是不对的Storyboard.SetTargetProperty(fxPSEditorView,新的PropertyPath(MarginProperty));这是正确的Storyboard.SetTargetProperty(animPSEditorView,新的PropertyPath(MarginProperty)); – 2011-12-16 08:58:24