[英]C# WPF: GradientStop.ColorProperty Animation Doesn't Work In Storyboard
[英]WPF Second Animation (StoryBoard) doesn't work
这是场景:我有一个Grid
和一个Button
。 网格有一个Show
Boolean 属性。 当用户单击按钮时,如果Show=false
则 Grid 变为Visible
。 当Show=true
Grid 变为Collapse
时。 当它的能见度改变时,我用 StoryBoard 为网格的Height
做一个StoryBoard
。
好的。 一切都很好。 当用户单击按钮时, Grid
出现 animation。 但是当再次点击时,animation 没有显示,只是发生了崩溃。
这是我的代码:
Storyboard growUpStory = new Storyboard();
Storyboard growDownStory = new Storyboard();
DoubleAnimation growUp, growDown;
在任何方法中:
height = Container.DesiredSize.Height;
growUp = new DoubleAnimation
{
From = 0,
To = height > MaxHeight ? MaxHeight : height,
Duration = new Duration(TimeSpan.FromSeconds(1)),
AutoReverse = false
};
Container.Visibility = Visibility.Collapsed;
growDown = new DoubleAnimation
{
From = height > MaxHeight ? MaxHeight : height,
To = 0,
Duration = new Duration(TimeSpan.FromSeconds(1)),
AutoReverse = false
};
growUpStory.Children.Add(growUp);
growDownStory.Children.Add(growDown);
当我调用事件时:
if (Show)
{
Storyboard.SetTarget(growUpStory, Container);
Storyboard.SetTargetProperty(growUpStory, new PropertyPath(Grid.HeightProperty));
growUpStory.Begin();
Container.Visibility = Visibility.Visible;
}
else
{
Storyboard.SetTarget(growDownStory, Container);
Storyboard.SetTargetProperty(growDownStory, new PropertyPath(Grid.HeightProperty));
growDownStory.Begin();
Container.Visibility = Visibility.Collapsed;
}
我尝试了很多方法,但无法解决。 我的问题在哪里? 你有什么想法吗? 谢谢。
XAML
动画是异步的,这意味着您在开始“growDownStory”animation 的同时折叠可见性。
根据您希望“growDownStory”animation 运行多长时间添加一些延迟。
例子:
growDownStory.Begin();
await Task.Delay(1000); // allow time for the animation to perform its visual
Container.Visibility = Visibility.Collapsed;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.