【问题标题】:Outlook Add-In and Disabling/Hiding Custom Menu ItemsOutlook 加载项和禁用/隐藏自定义菜单项
【发布时间】:2011-11-18 23:24:18
【问题描述】:

我创建了一个 Outlook 加载项,并且正在使用 XML 功能区配置文件来指定一个新选项卡和按钮。该按钮加载到 Outlook 中的新选项卡中。现在有时,根据用户我们希望能够隐藏或禁用这些按钮。通过 Outlook Interop api 禁用自定义选项卡上的菜单按钮的最简单方法是什么?

我的第一个猜测是,我需要在创建功能区后遍历一些命令栏集合,然后搜索我的菜单按钮,但我不确定这些集合在哪里。

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

【问题讨论】:

    标签: c# outlook ribbon outlook-addin office-interop


    【解决方案1】:

    很抱歉回答我自己的问题。终于想通了。在 xml 配置中,按钮/组/选项卡有一个 getVisible 回调。

    所以你需要做的就是在 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>
    

    并创建回调方法

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

    那么,如果在使用 Outlook 的过程中,您更改了按钮/选项卡/组的可见性设置,则需要在功能区上调用 Invalidate() 方法以便重新绘制功能区。即:

    this.ribbon.Invalidate();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 2012-09-24
      • 2020-07-14
      • 2014-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多