亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何檢查我的 VS 2017 擴展中的工具窗口是否隱藏

如何檢查我的 VS 2017 擴展中的工具窗口是否隱藏

C#
白豬掌柜的 2022-11-21 20:40:17
我正在為 Visual Studio 2017 開發一個擴展,其中包含自定義“toolwindow”。此“工具窗口”包含WPF control訂閱view model了Workspace.WorkspaceChanged和EnvDTE.DTE.Events.WindowEvents.WindowActivated事件。我知道當用戶關閉“toolwindow”時,它實際上并沒有被破壞,而是“隱藏”了。但是,它仍然對我的事件做出反應。所以,我想知道兩個問題的答案:如何檢查工具窗口是否被隱藏?我可以“關閉”工具窗口以便將其銷毀嗎?編輯:創建工具窗口的代碼:protected virtual TWindow OpenToolWindow(){        ThreadHelper.ThrowIfNotOnUIThread();        // Get the instance number 0 of this tool window. This window is single instance so this instance        // is actually the only one.        // The last flag is set to true so that if the tool window does not exists it will be created.        ToolWindowPane window = Package.FindToolWindow(typeof(TWindow), id: 0, create: true);        if (window?.Frame == null)        {            throw new NotSupportedException("Cannot create tool window");        }        IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());        return window as TWindow;}
查看完整描述

2 回答

?
富國滬深

TA貢獻1790條經驗 獲得超9個贊

要檢測工具窗口何時關閉,您可以從IVsWindowFrameNotify3繼承它并在 OnShow 方法中檢查 fShow == (int) __FRAMESHOW.FRAMESHOW_WinClosed。



查看完整回答
反對 回復 2022-11-21
?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

只是為了添加到@Sergey Vlasov 的回答 - 我發現了第二種方法,如果窗口被隱藏/顯示,則會收到通知。這是我的 WPF 控件視圖模型中的代碼。


EnvDTE.DTE dte = MyVSPackage.Instance.GetService<EnvDTE.DTE>();


// _visibilityEvents is a private field. 

// There is a recommendation to store VS events objects in a field 

// to prevent them from being GCed

_visibilityEvents = (dte?.Events as EnvDTE80.Events2)?.WindowVisibilityEvents;


if (_visibilityEvents != null)

{

    _visibilityEvents.WindowShowing += VisibilityEvents_WindowShowing;

    _visibilityEvents.WindowHiding += VisibilityEvents_WindowHiding;

}



查看完整回答
反對 回復 2022-11-21
  • 2 回答
  • 0 關注
  • 99 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號