Fading out a wpf window on close

前端 未结 5 880

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

5条回答
  •  不知归路
    2020-12-14 02:31

    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();
    }
    

提交回复
热议问题