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

Hepzibah C 0 Reputation points
2024-01-09T10:11:45.1433333+00:00

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. i can dock the window by using below snippet , but it always docking to bottom position. how can i change and where i should write to set programmatically

 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());
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,821 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,573 questions
Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
189 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 28,941 Reputation points Microsoft Vendor
    2024-01-11T06:04:51.58+00:00

    Hello @Hepzibah C ,

    Thanks for your reply.

    This document: VsDockStyle indicates that

    You cannot specify that a tool window is docked by default.

    A very close method to dock the custom tool window when it opens for the first time is to dock it with other windows like Solution Explorer, Output Window…

    An example(dock with Solution Explorer):

    Using following code:

    [ProvideToolWindow(typeof(ToolWindow1),
               Orientation = ToolWindowOrientation.Right,
               Window = "3ae79031-e1bc-11d0-8f78-00a0c9110057",
               Style = VsDockStyle.Tabbed)]
    

    Steps:

    1.Create a new VSIX project => right-click the project => Add => New Item…

    2.Select Tool Window => Add => open xxxxPackage.cs file => Modify above code

    3.Run the project => for the first time it opens, it docks on the right with Solution Explorer, if it doesn’t display, try to click View => Other Windows => ToolWindow1 to open it.

    BTW, as it works for the very first time, you may need to create and use a new project to test.

    Sincerely,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.