[英]Add two or more Tool Window into the same Visual Studio project
我試圖在Visual Studio中向VSPackage項目添加第二個工具窗口,我有一個工具窗口已經在Visual Studio提供的向導中創建,當創建VSPackage項目時,我正在網上瀏覽尋找一些教程這可以幫助我向現有的VSPackage項目添加第二個工具窗口。 我已經閱讀了幾篇關於工具窗口的文章,但我無法得到解決方案。 我創建了一個新類
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Shell;
namespace Company.VSPackage1
{
[Guid("759c7eb3-6850-4cce-b765-2d5902a90918")]
public class OtherToolWindow : ToolWindowPane
{
public OtherToolWindow() :
base(null)
{
this.Caption = Resources.OtherToolWindowTitle;
this.BitmapResourceID = 301;
this.BitmapIndex = 1;
}
}
}
然后我修改了幾次繼承自Package的類,但是我做錯了或丟失了
using System;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.ComponentModel.Design;
using Microsoft.Win32;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;
namespace Company.VSPackage1
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
[ProvideMenuResource("Menus.ctmenu", 1)]
[ProvideToolWindow(typeof(MyToolWindow))]
[ProvideToolWindow(typeof(OtherToolWindow))]
[Guid(GuidList.guidVSPackage1PkgString)]
public sealed class VSPackage1Package : Package
{
public VSPackage1Package()
{
Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
}
private void ShowToolWindow(object sender, EventArgs e)
{
ToolWindowPane window = this.FindToolWindow(typeof(MyToolWindow), 0, true);
if ((null == window) || (null == window.Frame))
{
throw new NotSupportedException(Resources.CanNotCreateWindow);
}
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
}
private void ShowOtherToolWindow(object sender, EventArgs e)
{
ToolWindowPane otherWindow = this.FindToolWindow(typeof(OtherToolWindow), 0, true);
if ((null == otherWindow) || (null == otherWindow.Frame))
{
throw new NotSupportedException(Resources.CanNotCreateWindow);
}
IVsWindowFrame otherWindowFrame = (IVsWindowFrame)otherWindow.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(otherWindowFrame.Show());
}
protected override void Initialize()
{
Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
base.Initialize();
// Add our command handlers for menu (commands must exist in the .vsct file)
OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if ( null != mcs )
{
// Create the command for the tool window
CommandID toolwndCommandID = new CommandID(GuidList.guidVSPackage1CmdSet, (int)PkgCmdIDList.cmdidMyTool);
MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandID);
CommandID toolwndCommandID2 = new CommandID(GuidList.guidVSPackage1CmdSet2, (int)PkgCmdIDList.cmdidMyTool2);
MenuCommand menuToolWin2 = new MenuCommand(ShowOtherToolWindow, toolwndCommandID2);
mcs.AddCommand( menuToolWin );
mcs.AddCommand(menuToolWin2);
}
}
}
}
我只想在visual studio的同一個vspackage中添加多個工具窗口
這肯定是錯的:
CommandID toolwndCommandID2 = new CommandID(GuidList.guidVSPackage1CmdSet2, (int)PkgCmdIDList.cmdidMyTool2);
它應該是:
CommandID toolwndCommandID2 = new CommandID(GuidList.guidVSPackage1CmdSet, (int)PkgCmdIDList.cmdidMyTool2);
您需要修復.vsct文件和Guids.cs文件,您尚未發布。
也就是說,一個包有一個命令集,它可以有幾個命令。
FWIW,我正在開發一個關於創建工具窗口的教程。 這里是:
HOWTO:在Visual Studio包中創建一個帶有ToolWindowPane類的工具窗口http://www.visualstudioextensibility.com/2015/02/20/mz-tools-articles-series-howto-create-a-toolwindow-with-a- toolwindowpane級-IN-A-視覺工作室封裝/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.