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。但是它不會將一組對象作爲第一個參數。 任何想法如何運行這個動畫將是很好的!謝謝
我發現自己的錯誤:這是不對的Storyboard.SetTargetProperty(fxPSEditorView,新的PropertyPath(MarginProperty));這是正確的Storyboard.SetTargetProperty(animPSEditorView,新的PropertyPath(MarginProperty)); – 2011-12-16 08:58:24