WPF動畫

August 3, 2014 at 4:58 PMAdmin

我建了改為Panel的寬度動畫功能,用戶只要點擊最小化按鈕,Panel會慢慢窄。造成一個收縮的效果。

我發現最好的辦法是使用DoubleAnimationUsingKeyFrames。這種動畫可以針對任何Double為其值,例如寬度的屬性。最後,把它放入StoryBoard。就如下例:

DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
LinearDoubleKeyFrame ad3 = new LinearDoubleKeyFrame();
ad3.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0, 0, 0));
ad3.Value = ActualWidth;
LinearDoubleKeyFrame ad = new LinearDoubleKeyFrame();
ad.KeyTime = KeyTime.FromTimeSpan(new TimeSpan(0,0,6));
ad.Value = 0;
Storyboard strbStoryboard = new Storyboard();
strbStoryboard.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("(FrameworkElement.Width)"));
Storyboard.Begin(this);

這個例子是從我的開源項目,advgencontactmanager

Posted in:

Tags:

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading