2011-09-16 60 views
4

我創建了一個Outlook加載項,並且我正在使用XML功能區配置文件來指定一個新選項卡和按鈕。該按鈕加載到Outlook中的新選項卡中。現在有時候,基於用戶,我們希望能夠隱藏或禁用這些按鈕。通過Outlook Interop api禁用自定義選項卡上的菜單按鈕的最簡單方法是什麼?Outlook加載項和禁用/隱藏自定義菜單項目

我的第一個猜測是,我需要在創建功能區後遍歷一些命令欄集合,然後搜索我的菜單按鈕,但我不確定這些集合的位置。

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

回答

6

對不起回答我自己的問題。最後算出來了。在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()方法,以便重新繪製功能區。 IE:

this.ribbon.Invalidate();