Outlook 功能区加载时 Application.ActiveInspector() 为 Null

发布于 2024-07-21 04:50:50 字数 184 浏览 5 评论 0原文

是否可以在功能区加载时访问 ActiveInspector。 当我使用自定义表单时,Application.ActiveInspector() 返回正确的值,但对于默认联系表单则不返回正确的值。

我需要 ActiveInspector 根据 ActiveInspector().CurrentItem 中的属性值自定义功能区按钮。

Is it possible to access the ActiveInspector at the time of ribbon load. Application.ActiveInspector() returns proper value when I use custom form but does not for default contact form.

I need the ActiveInspector to customize ribbon button depending on a property value in ActiveInspector().CurrentItem.

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

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

发布评论

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

评论(2

数理化全能战士 2024-07-28 04:50:51

您能否处理 Inspectors 集合的 NewInspector 事件,然后将其保留在可以从功能区加载事件访问的静态字段中(可能应该使用 Wea​​kReference)?

我还没有使用 Outlook 进行任何功能区自定义,但我在我的旧 Tablet PC 产品 TEO 中与检查员一起进行了大量工作。 与它们一起工作是一件很痛苦的事情,但你不想做的主要事情就是长时间保留 Inspector 参考,因为关闭 Outlook 或取消挂起的编辑时你会遇到各种奇怪的问题。

Can you handle the NewInspector event of the Inspectors collection, then hold onto that in a static field (probably should use a WeakReference) that you can access from the ribbon load event?

I haven't done any Ribbon customization with Outlook but I've done extensive work with inspectors in my old Tablet PC product, TEO. They're a pain in the ass to work with but the main thing you don't wanna do is hang onto an Inspector reference too long because you'll get all kinds of weird problems with shutting down Outlook or canceling pending edits.

凉墨 2024-07-28 04:50:50

我对上面的内容做了一些改动,因为我维护了开放检查员的列表(我将检查员包装起来并将其保留在列表中)。
将它们添加到新的检查器事件中,并在连线关闭事件关闭时将其删除。

在我的功能区代码中,我有一个静态方法 FindOutlookInspector,它使用功能区的 control.context 查找检查器。

沿着这些思路..

OutlookInspector 是我包装的检查器类,但您可能不需要它等。
另外我只关心邮件项目

void _inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) {
    OutlookItem olItem = null;
    try {
        object newitem = Inspector.CurrentItem;
        olItem = new OutlookItem(newitem);
        if (olItem.Class == Outlook.OlObjectClass.olMail && olItem.MessageClass == "IPM.Note") {

            OutlookInspector existingWindow = FindOutlookInspector(Inspector);

            if (existingWindow == null) {
                OutlookInspector window = new OutlookInspector(Inspector);

                window.Close += new EventHandler(WrappedWindow_Close);
                _windows.Add(window);
            }

        } catch (Exception ex) {
            throw ex;
        }
    }

    void WrappedWindow_Close(object sender, EventArgs e) {
        OutlookInspector window = (OutlookInspector) sender;
        window.Close -= WrappedWindow_Close;
        _windows.Remove(window);
    }

    internal static OutlookInspector FindOutlookInspector(object window) {
        foreach(OutlookInspector inspector in _windows) {
            if (inspector.Window == window) {
                return inspector;
            }
        }
        return null;
    }

然后在功能区代码中我可以调用 FindOutlookInspector 来获取包装的检查器

 OutlookInspector window = ThisAddIn.FindOutlookInspector(control.Context);

I do a slight variation on the above in that I maintain list of the open inspectors (I wrap the inspector and keep that in the list).
Adding them on the new inspector event and removing them on a wired up close event close.

In my ribbon code I have a static method FindOutlookInspector that finds the inspector using the control.context of the ribbon.

Something along these lines ..

OutlookInspector is my wrapped inspector class but you may not need that etc.
Also I only care about Mail Items

void _inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) {
    OutlookItem olItem = null;
    try {
        object newitem = Inspector.CurrentItem;
        olItem = new OutlookItem(newitem);
        if (olItem.Class == Outlook.OlObjectClass.olMail && olItem.MessageClass == "IPM.Note") {

            OutlookInspector existingWindow = FindOutlookInspector(Inspector);

            if (existingWindow == null) {
                OutlookInspector window = new OutlookInspector(Inspector);

                window.Close += new EventHandler(WrappedWindow_Close);
                _windows.Add(window);
            }

        } catch (Exception ex) {
            throw ex;
        }
    }

    void WrappedWindow_Close(object sender, EventArgs e) {
        OutlookInspector window = (OutlookInspector) sender;
        window.Close -= WrappedWindow_Close;
        _windows.Remove(window);
    }

    internal static OutlookInspector FindOutlookInspector(object window) {
        foreach(OutlookInspector inspector in _windows) {
            if (inspector.Window == window) {
                return inspector;
            }
        }
        return null;
    }

Then in the ribbon code I can call FindOutlookInspector to get the wrapped inspector

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