在 Visual Studio 上打开一个自定义工具 Window,而不是从“视图”菜单中调用它
Open a Custom Tool Window on Visual Studio without calling it from the View menu
我看到通过 Visual Studio 扩展工具,您可以添加自定义命令,例如灯泡、工具 Windows(如属性面板)等等...
基本上我正在尝试创建一个自定义工具 Window,它不是从 View -> Other Windows menu 而是从一个按钮打开的我自己创建了 UI。
为此,我尝试创建一个基本上调用我的 PaneResultsPackage class 的委托,然后调用应该触发所有逻辑的 Initialize() 方法。但是,它不会生成窗格,因为包对象似乎是空的。
这基本上就是class:
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(ResourceAnalysisPaneResults))]
[Guid(ResourceAnalysisPaneResultsPackage.PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
public sealed class ResourceAnalysisPaneResultsPackage : Package
{
/// <summary>
/// ResourceAnalysisPaneResultsPackage GUID string.
/// </summary>
public const string PackageGuidString = "29677396-e861-4672-804e-75cc557f1874";
/// <summary>
/// Initializes a new instance of the <see cref="ResourceAnalysisPaneResults"/> class.
/// </summary>
public ResourceAnalysisPaneResultsPackage()
{
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
ResourceAnalysisPaneResultsCommand.Initialize(this);
base.Initialize();
}
** Here is the call to the delegate**
public void OnSchemaAnalyzed(object source, EventArgs e)
{
Initialize();
}
#endregion
}
除用于我创建的委托的 OnSchemaAnalyzed 方法外,所有这些代码都是预填充的。
如何在不通过视图 -> Windows 选项卡调用的情况下拥有不包含空属性的包对象?
那么正确的做法是什么?
您不应该自己调用 Initialize - 它会在实例化您的包时由 Visual Studio 自动调用。
要显示工具 window,请查看将工具 window 添加到项目时默认创建的 ShowToolWindow 方法:
ToolWindowPane window = this.package.FindToolWindow(typeof(ResourceAnalysisPaneResults), 0, true);
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
windowFrame.Show();
我看到通过 Visual Studio 扩展工具,您可以添加自定义命令,例如灯泡、工具 Windows(如属性面板)等等...
基本上我正在尝试创建一个自定义工具 Window,它不是从 View -> Other Windows menu 而是从一个按钮打开的我自己创建了 UI。 为此,我尝试创建一个基本上调用我的 PaneResultsPackage class 的委托,然后调用应该触发所有逻辑的 Initialize() 方法。但是,它不会生成窗格,因为包对象似乎是空的。
这基本上就是class:
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)] // Info on this package for Help/About
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(ResourceAnalysisPaneResults))]
[Guid(ResourceAnalysisPaneResultsPackage.PackageGuidString)]
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1650:ElementDocumentationMustBeSpelledCorrectly", Justification = "pkgdef, VS and vsixmanifest are valid VS terms")]
public sealed class ResourceAnalysisPaneResultsPackage : Package
{
/// <summary>
/// ResourceAnalysisPaneResultsPackage GUID string.
/// </summary>
public const string PackageGuidString = "29677396-e861-4672-804e-75cc557f1874";
/// <summary>
/// Initializes a new instance of the <see cref="ResourceAnalysisPaneResults"/> class.
/// </summary>
public ResourceAnalysisPaneResultsPackage()
{
// Inside this method you can place any initialization code that does not require
// any Visual Studio service because at this point the package object is created but
// not sited yet inside Visual Studio environment. The place to do all the other
// initialization is the Initialize method.
}
#region Package Members
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
protected override void Initialize()
{
ResourceAnalysisPaneResultsCommand.Initialize(this);
base.Initialize();
}
** Here is the call to the delegate**
public void OnSchemaAnalyzed(object source, EventArgs e)
{
Initialize();
}
#endregion
}
除用于我创建的委托的 OnSchemaAnalyzed 方法外,所有这些代码都是预填充的。
如何在不通过视图 -> Windows 选项卡调用的情况下拥有不包含空属性的包对象?
那么正确的做法是什么?
您不应该自己调用 Initialize - 它会在实例化您的包时由 Visual Studio 自动调用。
要显示工具 window,请查看将工具 window 添加到项目时默认创建的 ShowToolWindow 方法:
ToolWindowPane window = this.package.FindToolWindow(typeof(ResourceAnalysisPaneResults), 0, true);
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
windowFrame.Show();