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

Asked

Viewed 101 times

1

The correct question would be: how to Open only one instance of this window.

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

Dim newWindow As New Window1
newWindow.Show()

in windows Forms would only put window1.show direct without serimonia, 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 WPF I can’t get the same result

1 answer

2


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.