How do you tell if a WPF Window is closed?

前端 未结 7 2019
情深已故
情深已故 2020-12-09 07:27

I\'m working on an application that displays some child windows which can either be closed by the user or are automatically closed. While debugging some exceptions that wer

7条回答
  •  爱一瞬间的悲伤
    2020-12-09 07:54

    You can add a non static property to the WindowClass bool IsClosed, and set true on the Closed event:

    public partial class MyWindow : Window
    {
        public bool IsClosed { get; set; } = false;
        public MyWindow()
        {
            Closed += MyWindow_Closed;
            InitializeComponent();
        }
    }    
    
    private void MyWindow_Closed(object sender, EventArgs e)
    {
       IsClosed = true;
    }
    

提交回复
热议问题