c# - 替代 TextViewCreated,例如(TextViewChanged)?

标签 c# textview vsx

我正在用 C# 创建一个小型 Visual Studio 2010 扩展,它使用 IWpfTextViewCreationListener 和 TextViewCreated 在 VS 环境中打开新的 TextView 时进行捕获。我遇到的问题是,此方法仅在通过 VS 解决方案资源管理器窗口打开新窗口时触发,而在 VS 启动时已经包含打开的窗口和切换窗口选项卡时不会触发。我试过寻找类似 TextViewChanged 的​​东西,但找不到这样的方法。 Is there anyway to capture the new TextView when another tabbed window is selected?

如有任何帮助,我们将不胜感激。

此问题也已发布在 MSDN VS Extensibility 论坛上: VSX 2010 - Alternative to TextViewCreated such as (TextViewChanged)?

谢谢

约翰

最佳答案

没有 TextViewCreated,但如果您在创建时注册到 IWpfTextView.GotAggregateFocus,您将获得文件之间每次切换的 Hook :

    public void TextViewCreated(IWpfTextView textView)
    {
        textView.GotAggregateFocus += TextViewCameToFocus;
        // Do stuff when a new IWpfTextView is created...
    }

    void TextViewCameToFocus(object sender, EventArgs e)
    {
        var focusedTextView = (IWpfTextView)sender;

        // Do stuff when a specific IWpfTextView comes to focus...
    }

如果您希望能够将激发的事件与每个 TextView 的逻辑联系起来,您可能还需要跟踪 IWpfTextView 对象。

关于c# - 替代 TextViewCreated,例如(TextViewChanged)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3779198/

相关文章:

c# - 使用带有 C# 的 Selenium WebDriver 全屏打开浏览器窗口

c# - 线程 MVC 6 .net 5

android - 每行单独的行间距

android - TextView:让它截断而不考虑单词之间的空格

visual-studio - 在构建期间从 Visual Studio 扩展传递自定义项目属性

c# - 打开内存中的 VS 2005 解决方案文件 (.sln)

c# - resharper 忽略特定问题

c# - 角色实例的启动时间比预期要长

android - 字符串.xml : How to remove underlining from the space preceding an <u> tag?

visual-studio - 如何部署和注册支持多个版本的 Visual Studio(2005、2008、2010)的 VSPackage?