Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Outlook功能区按钮在Outlook加载项中未正确显示_C#_Outlook_Outlook Addin - Fatal编程技术网

C# Outlook功能区按钮在Outlook加载项中未正确显示

C# Outlook功能区按钮在Outlook加载项中未正确显示,c#,outlook,outlook-addin,C#,Outlook,Outlook Addin,代码优先: 编程向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_tit

代码优先:

编程向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);
    }
}
private void事件(参考bool asd)
{
Outlook.Selection Selection=Globals.ThisAddIn.Application.ActiveExplorer().Selection;
if(selection.OfType().Count()==1)
{
Outlook.ContactItem contact=selection.OfType().FirstOrDefault();
showOrHide(联系人);
}
}
您可以看到,我正在尝试显示/隐藏ribbonbar中的按钮,具体取决于联系人是否具有特定的电话号码类型

第一次打开联系人时,Ribbon按钮正确显示/隐藏:

但当我选择另一个联系人(或相同联系人)时,它会显示我的所有按钮,而不显示标签图像,即使它们可见=false:

我猜outlook在我第一次关闭联系人窗口时会破坏我的ribbonbuttons。所以当我打开另一个的时候,色带按钮都被弄乱了。 有人有主意吗?

使用方法将功能区控件添加到加载项中。这是相当可靠的

将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”属性声明回调方法,可以使功能区控件无效并控制其可见性