Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. testing if window is loaded.

testing if window is loaded.

Scheduled Pinned Locked Moved WPF
csharpwpftestingbeta-testinghelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gritter
    wrote on last edited by
    #1

    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.

    G I 2 Replies Last reply
    0
    • G gritter

      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.

      G Offline
      G Offline
      gritter
      wrote on last edited by
      #2

      I changed the line with TryFindResource() to:

      Dim nextWindow As Window = CType(Application.Current.TryFindResource("Window3"), Window)

      The change made no difference. It still doesn't find the existing instance of Window3.

      1 Reply Last reply
      0
      • G gritter

        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 Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        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 If

        GetInstance = _currentInstance
        End Function

        Also, 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)

        G 1 Reply Last reply
        0
        • I Ian Shlasko

          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 If

          GetInstance = _currentInstance
          End Function

          Also, 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)

          G Offline
          G Offline
          gritter
          wrote on last edited by
          #4

          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.

          G 1 Reply Last reply
          0
          • G gritter

            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.

            G Offline
            G Offline
            gritter
            wrote on last edited by
            #5

            Actually I think I got. It's probably not the best way, but I can do what I need by playing with the "topmost" property. Thanks.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups