[英]Outlook Add-In and Disabling/Hiding Custom Menu Items
我已經創建了一個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;
}
很抱歉回答我自己的問題。 終於想通了。 在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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.