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

前端 未结 6 915
一整个雨季
一整个雨季 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:26

    I am not really a 'proper' programmer, however I have achieved this in a WPF application (not from a winforms one) by using the following:

    Dim wdwDetails As New detailsNew()
    Private Sub openNewDetails(ByVal recordID As String)
        wdwDetails.Owner = Me
        wdwDetails.recordID = recordID
        wdwDetails.WindowStartupLocation = Windows.WindowStartupLocation.CenterOwner
        wdwDetails.Show()
    End Sub
    

    Essentially because I am creating the window object outside of the sub that opens it, there will only be a single window. Any new call to the window open sub will use the same object. But I guess that is what Thomas is referring to also.

    Like I said, not sure if this will help you or not though.

提交回复
热议问题