testing if window is loaded.
-
I am writing a WPF app that loops thru a series of windows. The first time thru, I need to create the next window, but on subsequent times, I want it to re-display the previously created window. I believe the function TryFindResource() should help me do this, but it's not working. See code below.
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim nextWindow As Window = CType(TryFindResource("Window3"), Window) If (nextWindow Is Nothing) Then nextWindow = New Window3 nextWindow.Show() Else nextWindow.Show() End If End Sub
Appreciate any help with this. Yes, this is my first WPF app.
-
I am writing a WPF app that loops thru a series of windows. The first time thru, I need to create the next window, but on subsequent times, I want it to re-display the previously created window. I believe the function TryFindResource() should help me do this, but it's not working. See code below.
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim nextWindow As Window = CType(TryFindResource("Window3"), Window) If (nextWindow Is Nothing) Then nextWindow = New Window3 nextWindow.Show() Else nextWindow.Show() End If End Sub
Appreciate any help with this. Yes, this is my first WPF app.
-
I am writing a WPF app that loops thru a series of windows. The first time thru, I need to create the next window, but on subsequent times, I want it to re-display the previously created window. I believe the function TryFindResource() should help me do this, but it's not working. See code below.
Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim nextWindow As Window = CType(TryFindResource("Window3"), Window) If (nextWindow Is Nothing) Then nextWindow = New Window3 nextWindow.Show() Else nextWindow.Show() End If End Sub
Appreciate any help with this. Yes, this is my first WPF app.
Try a static/shared field - These are related to the class itself, not to the instance of the class: In the Window3 code:
Private Shared _currentInstance as Window3
Public Shared Function GetInstance() As Window3
If _currentInstance Is Nothing Then
_currentInstance = New Window3
End IfGetInstance = _currentInstance
End FunctionAlso, be sure to add code to the OnClosing, or some similar location, to set _currentInstance back to Nothing if you close Window3. And in your btnGo code:
Window3.GetInstance().Show()
Oh, and might want to consider giving Window3 a more meaningful name.
Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)
-
Try a static/shared field - These are related to the class itself, not to the instance of the class: In the Window3 code:
Private Shared _currentInstance as Window3
Public Shared Function GetInstance() As Window3
If _currentInstance Is Nothing Then
_currentInstance = New Window3
End IfGetInstance = _currentInstance
End FunctionAlso, be sure to add code to the OnClosing, or some similar location, to set _currentInstance back to Nothing if you close Window3. And in your btnGo code:
Window3.GetInstance().Show()
Oh, and might want to consider giving Window3 a more meaningful name.
Proud to have finally moved to the A-Ark. Which one are you in? Author of Guardians of Xen (Sci-Fi/Fantasy novel)
-
Thanks! That works, except it does shift focus to the "called window". If you can help me out here too, I would appreciate it. WPF makes me feel pretty helpless. I didn't realize it was so different from WinForms.