2013-02-23 20 views
1

代碼首先正確顯示:展望ribbonbuttons不在Outlook插件

Programmaticaly添加按鈕一個ribbonbar:

for (int i = 0; i < titles.Length; i++) 
{ 
    RibbonButton button = this.Factory.CreateRibbonButton(); 
    button.Visible = false; 
    button.Label = titles[i]; 
    button.Image = OutlookAddIn1.Properties.Resources.Sans_titre_5; 
    button.ControlSize = Microsoft.Office.Core.RibbonControlSize.RibbonControlSizeLarge; 
    this.group1.Items.Add(button); 
} 

顯示/隱藏一些按鈕編程:

private void showOrHide(contact){ 
    // Building a phone array with the contact infos... 
    RibbonButton button = Globals.Ribbons.Ribbon1.ribbonButtons.ElementAt(i).Value; 
    button.Visible = button.Enabled = phones[i] != null; 
} 

我在所有contactItems.open上綁定了一個事件它調用此方法:

private void Event(ref bool asd) 
{ 
    Outlook.Selection selection = Globals.ThisAddIn.Application.ActiveExplorer().Selection; 
    if (selection.OfType<Outlook.ContactItem>().Count() == 1) 
    { 
     Outlook.ContactItem contact = selection.OfType<Outlook.ContactItem>().FirstOrDefault(); 
     showOrHide(contact); 
    } 
} 

擁有你所看到的,我想在我的ribbonbar顯示/隱藏按鈕取決於如果聯繫人有一定的電話號碼類型與否。

我第一次打開一個接觸時,ribbonbuttons被正確顯示/隱藏:

It works

但是,當我選擇另一接觸(或相同的),則顯示我的所有的按鈕,而沒有圖像標籤,即使它們是可見=假:

Doesn't work.

我的猜測是,前景打破我ribbonbuttons,當我閉上接觸窗口的第一次。所以當我打開另一個時,ribbonbuttons都搞亂了。 任何人有想法?

回答

-1

使用this方法將色帶控件添加到加載項。這是相當可靠的。

將Visual Studio中的功能區xml添加到您的解決方案,然後您可以將控件添加到您的功能區,如下所示。

<tab idMso="TabAddIns"> 
    <group id="ContentGroup" label="Content"> 
     <button id="textButton" label="Insert Text" 
      screentip="Text" onAction="OnTextButton" 
      supertip="Inserts text at the cursor location."/> 
     <button id="tableButton" label="Insert Table" 
      screentip="Table" onAction="OnTableButton" 
      supertip="Inserts a table at the cursor location."/> 
    </group> 
</tab> 

您可以在運行時爲事件定義回調併爲它們聲明標籤和其他屬性。通過聲明控件的「getVisible」屬性的回調方法,可以使功能區控件失效並控制其可見性。