justcla / VSWindowManager

Visual Studio extension for managing tool windows. Provides a menu button in the status bar with access to popular windows and window layout features.
MIT License
4 stars 2 forks source link

GetStatusBarDockPanel() return null #9

Closed zc910704 closed 3 years ago

zc910704 commented 3 years ago

hello, I just read your code and can't understand how does this function work. does it mean that get the dockpanel of statusbar where i can put my own control into it? and In my visual studio 2019 environment, it just return null. can you explain it ? thx.

 private static DockPanel GetStatusBarDockPanel()
        {
            DependencyObject dd = VisualTreeHelper.GetChild(Application.Current.MainWindow, 0);
            DependencyObject ddd = VisualTreeHelper.GetChild(dd, 0);

            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(ddd); i++)
            {
                object o = VisualTreeHelper.GetChild(ddd, i);
                if (o != null && o is DockPanel)
                {
                    DockPanel dockPanel = o as DockPanel;
                    if (dockPanel.Name == "StatusBarPanel")
                    {
                        return dockPanel;
                    }
                }
            }
            return null;
        }
zc910704 commented 3 years ago

Already got the answer. Just watch the vs visual tree and query for the statusbar dockpanel. the visual studio may change it layout so it can't work in vs 2019.

justcla commented 3 years ago

So the code scans all the DockPanels in Visual Studio looking for the one called "StatusBarPanel". It returns null if it can't find one.

If you say that it's returning null when you run it in Visual Studio 2019, then perhaps they have removed or renamed the StatusBarPanel. That's annoying. I was not expecting it to change. I'll check out the VS tree and see what they are calling it now.

Your message has prompted me to update the extension for VS2019. I'm working on it today. Thanks for your interest.

zc910704 commented 3 years ago

This seems worked for me .It return the correct StatusBarPanel in my visual studio 2019.

DependencyObject rootGrid = VisualTreeHelper.GetChild(Application.Current.MainWindow, 0);
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(rootGrid); i++)
{
    object o = VisualTreeHelper.GetChild(rootGrid, i);
    if (o != null && o is DockPanel)
    {
         DockPanel dockPanel = o as DockPanel;
         if (dockPanel.Name == "StatusBarPanel")
         {
            return dockPanel;
         }
    }
}
justcla commented 3 years ago

Thanks. I'll update my code as such.

justcla commented 3 years ago

Thanks again for the code fix for the Status Bar Panel. Works beautifully! You're a legend. Thanks mate!

Extension updated and upgraded for VS2019. Now available on the Marketplace.