How to open a new window only if it is not already open?

1

The correct question would be: How to open only one instance of this window.

About the program is a WPF and the language is VB.NET Currently the following code does not serve me, because if the user clicks 10 times the button will open 10 windows taking into account that Window1 is my Window1.xaml

Dim newWindow As New Window1
newWindow.Show()

In Windows Forms it would just put direct window1.show without serimony, that if the form was already open it would come up and if the form was closed it would reopen, but no new windows, no longer WPF I can not get the same result

    
asked by anonymous 21.09.2018 / 20:13

1 answer

1

Taking advantage of your colleague Tuxpilgrim , see if the following code helps:

Dim newWindow As Window1

newWindow = Application.OpenForms().OfType(Of Window1).FirstOrDefault

If newWindow Is Nothing Then
    newWindow = New Window1
    newWindow.Show()
Else
    newWindow.Select
End If
    
01.10.2018 / 11:59