mgaffigan / WpfAppBar

AppBar implementation for WPF
MIT License
70 stars 10 forks source link

WpfAppBar.UndockSample does not properly switch #9

Closed jschroedl closed 3 months ago

jschroedl commented 6 months ago

Build and run the Itp.WpfAppBar.UndockSample app. Click "Switch DockMode". The app docks, as expected. Click "Switch DockMode". The app un-docks, as expected. Click "Switch DockMode". A copy of the main window is shown instead of docking the current window.

The bug seems to be in the interaction of the DockMode property getter and ShowDockMode() in DockableWindowControl.cs. The getter checks for AppBarHost == null but when we leave the dock mode, this code runs:

                    if (AppBarHost != null)
                    {
                        AppBarHost.Content = null;
                        AppBarHost.Close();
                    }

This does not set AppBarHost to null so after this point, the DockMode will return Docked even though we've closed the appbar.

I think this is the proper fix:

                   if (AppBarHost != null)
                    {
                        AppBarHost.Content = null;
                        AppBarHost.Close();
                        AppBarHost = null;
                    }

A similar change is needed just below that for WindowHost:

                   if (WindowHost != null)
                    {
                        WindowHost.Content = null;
                        WindowHost.Close();
                        WindowHost = null;
                    }
mgaffigan commented 5 months ago

@jschroedl, Thanks for opening the issue! If you would like to submit a PR, I will review and merge.