How to dock a tool window when it open for the first time in vsix?

90 views Asked by At

I have created tool window in VSIX, now i need to dock that when it open for the first time as per the desired position we set and next time if user moves the tool window it should persist with that position as visual studio doing already.

The below code i have tried, but it always docking to bottom position. how can i change and where i should write to set programmatically.

code snippet:

ToolWindowPane window = this.package.FindToolWindow(typeof(ToolWindow1), 0, true);
if ((null == window) || (null == window.Frame))
{
    throw new NotSupportedException("Cannot create tool window");
}

IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
windowFrame.SetProperty((int)__VSFPROPID.VSFPROPID_FrameMode, (int)VSFRAMEMODE.VSFM_Dock);
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
1

There are 1 answers

0
Bowman Zhu-MSFT On

Generally, the correct way to achieve this is to use 'Properties of ProvideToolWindowAttribute'.

But I notice this:

https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.vsdockstyle?view=visualstudiosdk-2022&redirectedfrom=MSDN#remarks

enter image description here

You cannot specify that a tool window is docked by default. However, you can specify that it will dock when its title bar is double-clicked.

So the situation you encountered is expected, as it is already mentioned in the official document.