[英]Visual Studio 2017: Event-call when user changes tab
我正在尝试为VS(使用来自VSIX模板的SDK的扩展)编写XML代码的大纲视图,并且每当用户更改为其他代码视图/文档时,我都希望获得事件调用。
然后,我计划检查文档类型,如果它确实是xml文档,则创建并呈现一个交互式大纲。
我将如何创建这样的钩子,甚至有必要?
编辑
我尝试了以下实现,但被告知该对象不包含“ GetGlobalService”的定义
using System;
using System.Runtime.InteropServices;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
[Guid("bc4c5e8f-a492-4a44-9e57-ec9ad945140e")]
public class OutlineWindow : ToolWindowPane
{
private DTE dte;
public OutlineWindow() : base(null)
{
this.Caption = "OutlineWindow";
this.Content = new OutlineWindowControl();
dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
}
private void OnWindowActivated(Window gotFocus, Window lostFocus)
{
throw new NotImplementedException();
}
}
多亏了@stuartd,我才得以成功! 我的问题实际上是我把它放在错误的类中,继承使它混乱了。
public class OutlineManager
{
private DTE dte;
public OutlineManager()
{
dte = Package.GetGlobalService(typeof(DTE)) as DTE;
dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
}
private void OnWindowActivated(Window gotFocus, Window lostFocus)
{
//This is run when a new "window"(panel) gains focus (not only the code window though)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.