简体   繁体   English

Outlook加载项和禁用/隐藏自定义菜单项

[英]Outlook Add-In and Disabling/Hiding Custom Menu Items

I've created an Outlook Add-In, and I'm using an XML ribbon configuration file to specify a new tab, and button. 我已经创建了一个Outlook加载项,并且正在使用XML功能区配置文件来指定新的标签和按钮。 The button loads into a new tab within outlook. 该按钮将加载到Outlook中的新选项卡中。 Now sometimes, based on user we want to be able to hide or disable these buttons. 现在有时,根据用户的需要,我们希望能够隐藏或禁用这些按钮。 What's the simplest way to disable a menu button on a custom tab through the Outlook Interop api? 通过Outlook Interop API禁用自定义选项卡上的菜单按钮的最简单方法是什么?

My first guess is that I need to iterate through some command bar collections after my ribbon is created, and then search for my menu buttons, but I'm not sure where these collections are. 我的第一个猜测是,创建功能区后,我需要遍历一些命令栏集合,然后搜索菜单按钮,但是我不确定这些集合在哪里。

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    this.ribbon = new MyRibbon();

    // loop through tabs and ribbon items, look for my custom control, and enabled/disable specific buttons.

    return this.ribbon;
}

Sorry to answer my own question. 很抱歉回答我自己的问题。 Finally figured it out. 终于想通了。 Within the xml configuration there is a getVisible callback for buttons/groups/tabs. 在xml配置中,有一个针对按钮/组/标签的getVisible回调。

So all you need to do is add the callback in the xml, in my case I did it for a group: 因此,您需要做的就是在xml中添加回调,在我的情况下,我是针对一个组执行的:

<ribbon>
    <tabs>
      <tab idQ="myNs:myTab" label="My Label" >
          <group id="settingsGroup" label="Settings" getVisible="Control_Visible" >
              <button id="preferences" label="Preferences" image="configuration.png"
      screentip="Preferences" size="large" onAction="Settings_Click" supertip="Preferences" />
          </group>
      </tab>
    </tabs>
</ribbon>

and create a callback method 并创建一个回调方法

public bool Control_Visible(Office.IRibbonControl control)
{
    // In order to maintain a reference to the groups, I store the controls into a List<Office.IRibbonControl>.
    if(!this.groupControls.Contains(control))
    {
        this.groupControls.Add(control);
    }         

    // logic here to determine if it should return true or false to be visible...
    return true;
}

Then if during the use of outlook, you change the visibility setting of a button/tab/group, you need to call Invalidate() method on the ribbon so the ribbon redraws. 然后,如果在使用Outlook期间更改按钮/选项卡/组的可见性设置,则需要在功能区上调用Invalidate()方法,以便重新绘制功能区。 IE: IE浏览器:

this.ribbon.Invalidate();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM