0

Any easy one this time! Unresponsive WPF Window (as child)

Anonymous 10 years ago 0
This discussion was imported from CodePlex

BogusException wrote at 2014-07-10 03:26:

Experts,

Maybe I can get some help with this problem.

I have the Flights Demo code running fine in a WPF window-as long as that window is the "Startup URI" in my project's Properties -> Application -> Statup URI. It responds to mouse & keyboard as expected.

BUT, when I call that same class from code as a child of a parent WPF window, the child displays fine-and even animates-but is completely unresponsive to mouse & keyboard (except to close the window itself.

Now here is the weird part/hint that might tell the right person what the issue is:

When I close the child WPF window by clicking the close("x") widget, the window goes away, but I can see it still generating log entries!

Figuring on a thread-centric need, I have tried the following with no change in symptoms:

A. Just call it:
Dim wpfEarth As New vASA.TheEarthWindow
wpfEarth.Show()
B. Dispatchers:
(calling function/sub):
Dim thread = New Thread(New ThreadStart(AddressOf Me.DisplayEarthOnThread))
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
[...]
Private Sub DisplayEarthOnThread()
    Try
        Dim wpfEarth As New vASA.TheEarthWindow
        wpfEarth.Show()
        AddHandler wpfEarth.Closed, Sub(s, e) wpfEarth.Dispatcher.InvokeShutdown()
        System.Windows.Threading.Dispatcher.Run()
    Catch ex As Exception
        [...]
    End Try
End Sub
C. A ton of random variations on:
Dispatcher.Invoke(Sub()
    Dim wpfEarth As New vASA.TheEarthWindow
    wpfEarth.Show()
    AddHandler wpfEarth.Closed, Sub(sender2, e2) wpfEarth.Dispatcher.InvokeShutdown()
    System.Windows.Threading.Dispatcher.Run()
        End Sub)
D. This is SUPPOSED to kill the child window when it closes, but doesn't (still unresponsive like the above ones):
Dim newWindowThread As New Thread(New ThreadStart(Sub()
                                                                  ' When the window closes, shut down the dispatcher
                                                                  ' Start the Dispatcher Processing
                                                                  Dim tempWindow As New TheEarthWindow()
                                                                  AddHandler tempWindow.Closed, Sub(s2, e2) Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background)
                                                                  tempWindow.Show()
                                                                  System.Windows.Threading.Dispatcher.Run()
                                                              End Sub))
newWindowThread.SetApartmentState(ApartmentState.STA)
' Make the thread a background thread
newWindowThread.IsBackground = True
' Start the thread
newWindowThread.Start()
...
I could really use some insight... The parent is a stock WPF Window Project, and the Child is a HelixViewport3D window...

TIA!

pat
:)

BogusException wrote at 2014-07-11 17:40:

I'm such an idiot...

I always tell people, and it may well be a part of Murphy's or Man Law, but if you are really stuck, just ask someone for help. The fact that you posted a request for help almost guarantees it is a stupid, silly oversight on your part.

Now, with the answer at hand, it WAS a stupid, silly thing, and one which had (relatively) little to do with Helix.

Suitably embarrassed, let's just leave it at "RTFM", shall we? :)

Thanks!

pat
:)

objo wrote at 2014-07-11 21:42:

I am glad you solved it! I did not understand much of that code!
Maybe there should be a special forum for rubber duck problem solving? :-)