2

Visual Studio 拡張ツールを使用して、電球、ツール ウィンドウ (プロパティ パネルなど) などのカスタム コマンドを追加できることを確認しました...

基本的に、 View -> Other Windows メニューからではなく、自分の UI で作成したボタンから開くカスタム ツール ウィンドウを作成しようとしています。このために、基本的にPaneResultsPackageクラスを呼び出してから、すべてのロジックをトリガーすることになっている Initialize() メソッドを呼び出すデリゲートを作成しようとしました。ただし、パッケージ オブジェクトが空のように見えるため、Pane は生成されません。

これは基本的にクラスです:

    [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メソッドを除いて事前に設定されています。

[表示] -> [ウィンドウ] タブから呼び出さずに、null プロパティを含まないパッケージ オブジェクトを作成するにはどうすればよいですか?

それでは正しいアプローチは何ですか?

4

1 に答える 1

2

Initialize を自分で呼び出さないでください。パッケージをインスタンス化するときに、Visual Studio によって自動的に呼び出されます。

ツール ウィンドウを表示するには、ツール ウィンドウをプロジェクトに追加するときにデフォルトで作成される ShowToolWindow メソッドを確認します。

ToolWindowPane window = this.package.FindToolWindow(typeof(ResourceAnalysisPaneResults), 0, true);
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
windowFrame.Show();
于 2016-10-28T03:23:55.290 に答える