WPF Window.Loaded 和 Window.Closed
有两个事件触发器。其中之一是 RoundedEvent
Window.Loaded
,另一个是 Window.Closed
。 但两者不能同时工作。我该如何解决这个问题?
我的代码如下
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Closed">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="mainWindow"
Storyboard.TargetProperty="Left"
From="500" To="-200" Duration="0:0:1" >
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="mainWindow"
Storyboard.TargetProperty="Left"
From="-200" To="500" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
There are two event triggers. One of them is RoundedEvent
Window.Loaded
and the the other Window.Closed
.
But both of them does not work at the same time. How can I fix The problem?
My code is below
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Closed">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="mainWindow"
Storyboard.TargetProperty="Left"
From="500" To="-200" Duration="0:0:1" >
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="mainWindow"
Storyboard.TargetProperty="Left"
From="-200" To="500" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Window.Loaded
工作正常,问题是EventTriggers
仅适用于路由事件,但Window.Closed
不是路由事件(因为它是某种东西)这只能发生在一个窗口上)。我建议您通过处理 Window.Closed 事件来在代码隐藏中执行关闭动画,无论如何它都是有意义的,因为您需要等待动画结束才能真正关闭窗口。
Window.Loaded
works fine, the problem is thatEventTriggers
only work for routed events butWindow.Closed
is not routed event (since it is something that can only occur to a window).I suggest you do the closing animation in code-behind by handling the
Window.Closed
event, it makes sense anyway because you need to wait for the animation to end before you actually close the window.