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被正確顯示/隱藏:
但是,當我選擇另一接觸(或相同的),則顯示我的所有的按鈕,而沒有圖像標籤,即使它們是可見=假:
我的猜測是,前景打破我ribbonbuttons,當我閉上接觸窗口的第一次。所以當我打開另一個時,ribbonbuttons都搞亂了。 任何人有想法?