TextViewCreated 的替代品,例如 (TextViewChanged)?

发布于 2024-09-24 19:14:48 字数 538 浏览 3 评论 0原文

我正在 C# 中创建一个小型 Visual Studio 2010 扩展,它使用 IWpfTextViewCreationListener 和 TextViewCreated 来捕获在 VS 环境中打开新 TextView 的时间。我遇到的问题是,此方法仅在通过 VS 解决方案资源管理器窗口打开新窗口时触发,而在 VS 启动时已包含打开的窗口并切换窗口选项卡时不会触发。我尝试过寻找类似 TextViewChanged 的​​方法,但找不到这样的方法。当选择另一个选项卡式窗口时,是否有办法捕获新的 TextView ?

任何帮助将不胜感激。

这个问题也发布在 MSDN VS Extensibility 论坛上: VSX 2010 - TextViewCreated 的替代方案,例如(TextViewChanged)?

谢谢

约翰

I am creating a small Visual Studio 2010 extension in C# which uses the IWpfTextViewCreationListener and TextViewCreated to capture when a new TextView is opened in the VS environment. The problem I am having is that this method only fires when a new window is opened via the VS Solution Explorer window, and not fired when VS already contains opened windows when started, and switching window tabs. I have tried looking for something like TextViewChanged, but could not find such method. Is there anyway to capture the new TextView when another tabbed window is selected?

Any help would be greatly appreciated.

This question has also been posted on the MSDN VS Extensibility forum:
VSX 2010 - Alternative to TextViewCreated such as (TextViewChanged)?

Thanks

John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

庆幸我还是我 2024-10-01 19:14:48

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

    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...
    }

如果您希望能够在文件之间进行链接,您可能还需要跟踪 IWpfTextView 对象。向每个文本视图的逻辑触发事件。

There is no TextViewCreated, but if you register to IWpfTextView.GotAggregateFocus as it is created, you get a hook to every switch between files:

    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...
    }

You may also want to keep track of the IWpfTextView objects, if you want to be able to link between the fired events to your logic of each textview.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文