我正在创建一个带有需要显示的工具窗口的 Visual Studio 包扩展。我有一个代表我的工具窗口的类,它扩展了ToolWindowPane
:
[Guid(GuidList.guidToolWindowPersistanceString)]
public class MyToolWindow : ToolWindowPane
{
public MyToolWindow() :
base(null)
{
// Set the window title
this.Caption = "ToolWindowName";
// Set content of ToolWindow
base.Content = new MyControl();
}
}
MyControl
要在工具窗口中托管的 WPF 对象在哪里。Package
调用方法时从类中调用此无参数构造函数Package.CreateToolWindow
:
[ProvideToolWindow(typeof(MyToolWindow))]
public sealed class MyPackage : Package
{
//... Package initialization code...
private void ShowMainToolWindow()
{
var window = (ToolWindowPane)CreateToolWindow(typeof(MyToolWindow), 0); //how to pass parameters in tool window constructor??
if ((null == window) || (null == window.Frame))
throw new NotSupportedException(Resources.CanNotCreateWindow);
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
}
ToolWindowPane
所以问题是,有没有办法从对象中调用 a 的非无参数构造Package
函数?