2

I've seen that through the Visual Studio Extensibility tools, you can add custom commands such as Light Bulbs, Tool Windows (like the Properties panel) and so on...

Basically I am trying to create a Custom Tool Window that gets opened not from the View -> Other Windows menu but from a button that I have created on my own UI. For this, I tried to create a delegate that basically calls my PaneResultsPackage class and then calls the Initialize() method that is supposed to triger all the logic. However, it doesn't generate the Pane since the package object appears to be empty.

This is basically the 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
    }

All this code is prepopulated except the OnSchemaAnalyzed method that is for the delegate that I created.

How can I have a package object that does not contain null properties without invoking it through the View -> Windows tab?

What is the right approach then?

user3587624
  • 1,427
  • 5
  • 29
  • 60

1 Answers1

2

You shouldn't call Initialize yourself - it is automatically called by Visual Studio when instantiating your package.

To show a tool window, look at the ShowToolWindow method created by default when you add a tool window to your project:

ToolWindowPane window = this.package.FindToolWindow(typeof(ResourceAnalysisPaneResults), 0, true);
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
windowFrame.Show();
Sergey Vlasov
  • 26,641
  • 3
  • 64
  • 66