Show / Hide Table of Contents

Class BaseToolWindow<T>

A base class that makes it easier to use tool windows.

Inheritance
System.Object
BaseToolWindow<T>
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Community.VisualStudio.Toolkit
Assembly: Community.VisualStudio.Toolkit.dll
Syntax
public abstract class BaseToolWindow<T> : IToolWindowProvider where T : BaseToolWindow<T>, new()
Type Parameters
Name Description
T

The implementation type itself.

Examples
public class TestToolWindow : BaseToolWindow<TestToolWindow>
{
    public override string GetTitle(int toolWindowId) => "Test Window";

    public override Type PaneType => typeof(Pane);

    public override async Task<FrameworkElement> CreateAsync(int toolWindowId, CancellationToken cancellationToken)
    {
        await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
        var dte = await VS.GetDTEAsync();
        return new TestWindowControl(dte);
    }

    [Guid("d0050678-2e4f-4a93-adcb-af1370da941d")]
    public class Pane : ToolWindowPane
    {
        public Pane()
        {
            BitmapImageMoniker = KnownMonikers.Test;
        }
    }
}

Properties

| Improve this Doc View Source

Package

The package class that initialized this class.

Declaration
protected ToolkitPackage Package { get; }
Property Value
Type Description
ToolkitPackage
| Improve this Doc View Source

PaneType

Gets the type of Microsoft.VisualStudio.Shell.ToolWindowPane that will be created for this tool window.

Declaration
public abstract Type PaneType { get; }
Property Value
Type Description
System.Type

Methods

| Improve this Doc View Source

CreateAsync(Int32, CancellationToken)

Creates the UI element that will be shown in the tool window. Use this method to create the user control or any other UI element that you want to show in the tool window.

Declaration
public abstract Task<FrameworkElement> CreateAsync(int toolWindowId, CancellationToken cancellationToken)
Parameters
Type Name Description
System.Int32 toolWindowId

The ID of the tool window instance being created for a multi-instance tool window.

System.Threading.CancellationToken cancellationToken

The cancellation token to use when performing asynchronous operations.

Returns
Type Description
System.Threading.Tasks.Task<System.Windows.FrameworkElement>

The UI element to show in the tool window.

| Improve this Doc View Source

GetTitle(Int32)

Gets the title to show in the tool window.

Declaration
public abstract string GetTitle(int toolWindowId)
Parameters
Type Name Description
System.Int32 toolWindowId

The ID of the tool window for a multi-instance tool window.

Returns
Type Description
System.String
| Improve this Doc View Source

Initialize(ToolkitPackage)

Initializes the tool window. This method must be called from the Microsoft.VisualStudio.Shell.AsyncPackage.InitializeAsync(System.Threading.CancellationToken, System.IProgress<Microsoft.VisualStudio.Shell.ServiceProgressData>) method for the tool window to work.

Declaration
public static void Initialize(ToolkitPackage package)
Parameters
Type Name Description
ToolkitPackage package
| Improve this Doc View Source

ShowAsync(Int32, Boolean)

Shows the tool window. The tool window will be created if it does not already exist.

Declaration
public static Task<ToolWindowPane> ShowAsync(int id = 0, bool create = true)
Parameters
Type Name Description
System.Int32 id

The ID of the instance of the tool window for multi-instance tool windows.

System.Boolean create

Whether to create the tool window if it does not already exist.

Returns
Type Description
System.Threading.Tasks.Task<Microsoft.VisualStudio.Shell.ToolWindowPane>

A task that returns the Microsoft.VisualStudio.Shell.ToolWindowPane if the tool window already exists or was created, or a task that returns null if the tool window does not exist and was not created.

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX