I am creating a Visual Studio Package extension with a tool window that needs to be shown.
I have a class representing my tool window that extends 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();
}
}
where MyControl
is a WPF object to be hosted inside the tool window. This parameterless constructor is called from the Package
class when calling the method 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());
}
So the question is, is there any way to call a non-parameterless constructor of a ToolWindowPane
from the Package
object?
I don't think so.
There is nothing in here that indicates that it is:
https://learn.microsoft.com/en-us/visualstudio/extensibility/registering-a-tool-window https://www.mztools.com/articles/2015/MZ2015004.aspx