How do I know if a WPF window is opened

前端 未结 9 1905
天命终不由人
天命终不由人 2020-12-04 19:21

In a WPF window, how do I know if it is opened?

My goal to open only 1 instance of the window at the time.

So, my pseudo code in the parent window is:

<
9条回答
  •  被撕碎了的回忆
    2020-12-04 20:13

    public bool IsWindowOpen(string name = "") where T : Window
    {
        return Application.Current.Windows.OfType().Any(w => w.GetType().Name.Equals(name));               
    }
    

提交回复
热议问题