0
我需要通過C#動畫COLLAPSED
屬性。如何動畫倒塌的屬性?
我有它下面的代碼幾乎工作正常,除了沒有崩潰動畫。
任何線索?
var myElement = stackObj.Children[n];
Duration d = TimeSpan.FromSeconds(2);
Storyboard sb = new Storyboard() { Duration = d };
DoubleAnimation DA = new DoubleAnimation() { From = 1, To = 0, Duration = d };
ObjectAnimationUsingKeyFrames objectAnimationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
var discreteObjectKeyFrame = new DiscreteObjectKeyFrame()
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2))
};
objectAnimationUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);
Storyboard.SetTarget(objectAnimationUsingKeyFrames, myElement);
Storyboard.SetTargetProperty(objectAnimationUsingKeyFrames, new PropertyPath("Visibility.Collapsed"));
sb.Children.Add(DA);
string myObjectName = "r" + n;
Storyboard.SetTargetName(DA, myObjectName);
Storyboard.SetTargetProperty(DA, new PropertyPath("Opacity"));
sb.Begin(this);
n++;
我知道,在XAML應該像
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetProperty = "Opacity"
To = "0"
BeginTime = "0:0:0"
Duration = "0:0:2" />
<ObjectAnimationUsingKeyFrames
Storyboard.TargetProperty = "Visibility">
<DiscreteObjectKeyFrame KeyTime="0:0:2" Value="{x:Static Visibility.Collapsed}" />
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
但我不知道我要實現它的C#代碼。