淡出关闭时WPF窗口

淡出关闭时WPF窗口

本文介绍了淡出关闭时WPF窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想淡入/窗口出我的申请。在衰落发生在Window.Loaded,我想淡出对接近(或Window.Closed Window.Closing)。作品中的完美褪色但RoutedEvent不允许对Window.Closing。我应该使用什么关闭RoutedEvent?

I want to fade a window in/out in my application. Fading in occurs on Window.Loaded and I wanted to fade out on close (Window.Closed or Window.Closing). Fading in works perfectly but a RoutedEvent is not allowed on Window.Closing. What RoutedEvent should I be using for Close?

    <Window.Triggers>
        <EventTrigger RoutedEvent="Window.Loaded">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2" FillBehavior="HoldEnd" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="Window.Closing">
            <BeginStoryboard>
                <Storyboard>
                    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" />
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Window.Triggers>

我坐上去,值'Window.Closing'不能被分配​​到财产RoutedEvent一个错误。无效的事件名称。

I get a error on , Value 'Window.Closing' cannot be assigned to property 'RoutedEvent'. Invalid event name.

推荐答案

关闭不是路由事件,所以你不能在一个EventTrigger使用它。也许你可以在$ C $开始在ClosingEvent的处理情节提要C-后面,取消事件......类似的东西:

Closing is not a routed event, so you can't use it in an EventTrigger. Perhaps you could start the storyboard in the handler of the ClosingEvent in the code-behind and cancel the event... something like that :

private bool closeStoryBoardCompleted = false;

private void Window_Closing(object sender, CancelEventArgs e)
{
    if (!closeStoryBoardCompleted)
    {
        closeStoryBoard.Begin();
        e.Cancel = true;
    }
}

private void closeStoryBoard_Completed(object sender, EventArgs e)
{
    closeStoryBoardCompleted = true;
    this.Close();
}

这篇关于淡出关闭时WPF窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 12:03