资源管理器更改时的 Outlook VSTO 事件 [英] Outlook VSTO Event when the explorer changed
问题描述
我需要处理活动资源管理器对象上的选择更改事件.但是当我在功能区加载时订阅事件 Globals.ThisAddIn.Application.ActiveExplorer().SelectionChange
时,它只适用于当前活动的资源管理器.
是否有类似活动浏览器更改的事件?
我还尝试查看浏览器列表 Globals.ThisAddIn.Application.Explorers
,但该列表仅包含打开的浏览器.
首先,不要在从多点表达式返回的对象上设置事件处理程序(例如 Globals.ThisAddIn.Application.ActiveExplorer
) - 您将在临时变量上设置一个事件处理程序,该变量将在垃圾收集器到达时立即释放.该对象必须存储在一个变量中,保证在您的插件生命周期内保持活动状态.
其次,使用 Application.Explorers.NewExplorer
事件来跟踪新的资源管理器(您也可以使用 Explorer.Close
事件来释放特定的资源管理器对象).>
创建一个包装类,将 Explorer
对象存储为其成员(您可以将 Explorer
传递给其构造函数)并为 Explorer.SelectionChange 设置事件处理程序
和 Explorer.Close
事件.在您的插件中,声明一个包装器列表 (List
).启动时,循环遍历 Application.Explorers
集合中的所有资源管理器,并为 Explorers.NewExplorer
事件设置一个事件处理程序(同样,Explorers
必须在插件类级别声明以使其保持活动状态).
I need to work with the selection changed event on the active explorer object. But when I subscribe to the event Globals.ThisAddIn.Application.ActiveExplorer().SelectionChange
on ribbon load, it only works for the currently active explorer.
Is there an event like active explorer changed or so?
I also tried to go through the list of explorers Globals.ThisAddIn.Application.Explorers
, but that list only contains the explorers that were open.
Firstly, do not set an event handler on an object returned from a multiple dot expression (e.g. Globals.ThisAddIn.Application.ActiveExplorer
) - you'd be setting an event handler on a temporary variable that will be released as soon as Garbage Collector gets to it. The object must be stored in a variable guaranteed to stay alive for your addin lifetime.
Secondly, Use the Application.Explorers.NewExplorer
event to track new explorers (you can also use Explorer.Close
event to release a particular Explorer object).
Create a wrapper class that stores Explorer
object as its member (you can pass Explorer
to its constructor) and sets up event handlers for the Explorer.SelectionChange
and Explorer.Close
events. In your addin, declare a list of wrappers (List<MyExplorerWrapper>
). On startup, loop over all explorers in the Application.Explorers
collection and set up an event handler for the Explorers.NewExplorer
event (again, Explorers
must be declared on the addin class level to keep it alive).
这篇关于资源管理器更改时的 Outlook VSTO 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!