gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:42 27 4
gpt4 key购买 nike

我正在用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com