Outlook中的XML功能区-使它显示在特定窗口中 [英] XML Ribbon in Outlook - make it appear on a specific window

查看:151
本文介绍了Outlook中的XML功能区-使它显示在特定窗口中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用XML在Outlook中创建功能区,但在查找如何告诉我的加载项仅希望功能区显示在资源管理器窗口中时遇到麻烦.

I'm making my first attempt at creating a Ribbon in Outlook using XML and am having trouble locating specifically how to tell my add-in that I only want the ribbon to appear on Explorer windows.

建议?

谢谢.

我的Ribbon1.XML文件:

my Ribbon1.XML file:

    <?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
  <ribbon>
    <tabs>
      <tab idMso="TabAddIns">
        <group id="MyGroup"
               label="My Group">
          <button idMso="Delete"/>
        </group>
      </tab>
      <tab idMso="TabMail">
        <group idMso="GroupMoveActions"
               visible="false">
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

弹出的错误提示框显示:

The magical error box that pops up says:

测试OLaddin2中的CustomUI运行时错误

CustomUI Runtime Error in testingOLaddin2

Error found in CustomUI XML of "testingOLaddin2"

Line: 3
Column: 10
Error Code 0x80004005
Failed to find Office control by ID
ID: TabMail

每个请求,我的功能区生成代码:

Per request, my ribbon generation code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using Office = Microsoft.Office.Core;

using System.Diagnostics;

namespace testingOLaddin2
{
    [ComVisible(true)]
    public class Ribbon1 : Office.IRibbonExtensibility
    {
        private Office.IRibbonUI ribbon;

        public Ribbon1()
        {
        }

        #region IRibbonExtensibility Members

        public string GetCustomUI(string ribbonID)
        {
            return GetResourceText("testingOLaddin2.Ribbon1.xml");
        }

        #endregion

        #region Ribbon Callbacks
        //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1

        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
        {
            this.ribbon = ribbonUI;
        }


        #endregion

        #region Helpers

        private static string GetResourceText(string resourceName)
        {
            Assembly asm = Assembly.GetExecutingAssembly();
            string[] resourceNames = asm.GetManifestResourceNames();
            for (int i = 0; i < resourceNames.Length; ++i)
            {
                if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                {
                    using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                    {
                        if (resourceReader != null)
                        {
                            return resourceReader.ReadToEnd();
                        }
                    }
                }
            }
            return null;
        }

        #endregion
    }
}

推荐答案

这取决于您用来创建插件和功能区的方法.如果您使用

This depends on the method you use to create the addin and ribbon. If you are using the

IRibbonExtensibility.GetCustomUI(string RibbonId)

您可以通过仅在RibbonId参数具有值的情况下返回功能区xml来实现此目的

method you could accomplish this by only returning the ribbon xml if the RibbonId parameter has the value

"Microsoft.Outlook.Explorer"

修改

在代码中进行以下更改可能会起作用:

Following change in your code might work:

public string GetCustomUI(string ribbonID)
{
  if (ribbonID == "Microsoft.Outlook.Explorer")
    return GetResourceText("testingOLaddin2.Ribbon1.xml");

  return null; // if problems here, try return string.Empty
}

这篇关于Outlook中的XML功能区-使它显示在特定窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆