How can I make sure only one WPF Window is open at a time?

前端 未结 6 908
一整个雨季
一整个雨季 2021-01-14 08:06

I have a WPF window that I am launching from inside of a winform app. I only want to allow once instance of that WPF window to be open at a time, and not warn that user if t

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 08:34

    Here's something that's working for me.

        private About aboutWin;
        private void AboutOpenClicked(object sender, RoutedEventArgs e)
        {
           if(aboutWin == null)
           {
               aboutWin = new About();
               aboutWin.Closed += (a, b) => aboutWin = null;
               aboutWin.Show();
           }
           else
           {
    
               aboutWin.Show();  
           }
    
        }
    

提交回复
热议问题