对于每个接收者,用户在外接程序的“收件人”字段中键入将创建一个对应的RibbonDropDown
项,并将其添加到RibbonGallery
中。触发事件后,将执行以下代码:
private void updateGallery(string name, string address, string gender, double probability)
{
Globals.Ribbons.Ribbon1.RibbonUI.Invalidate();
Microsoft.Office.Tools.Ribbon.RibbonDropDownItem itemReceiver = Globals.Factory.GetRibbonFactory().CreateRibbonDropDownItem();
itemReceiver.ScreenTip = address;
itemReceiver.Tag = gender;
itemReceiver.Label = name;
itemReceiver.SuperTip = (probability * 100).ToString() + " % Probability";
Globals.Ribbons.Ribbon1.gallery1.Items.Add(itemReceiver);
}
注意: gallery1 是RibbonGallery
。
这是用户将会看到的:
如您在第一张图片中所见,UI可以按预期工作。用户创建新邮件时,图库不再更新其项目。该代码仍将执行,但是新项目将不会显示在UI中。
这是用户将会看到的:
我尝试使用Invalidate
,但是我做错了或者/并且似乎不起作用。加载项还会根据 gallery1 的内容生成称呼。在picture 2中,您可以看到邮件主体创建了一个称呼,因此 gallery1 的内容是合法的,但根本没有显示。
这是XML:
<?xml version="1.0" encoding="UTF-8"?>
<customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Smart Mail">
<group id="groupUnsub" label="Unsubscribe">
<button id="btnUnsub" imageMso="JunkEmailOptions" onAction="button1_Click" supertip="Use this function to unsubscribe." label="Cancel Mailinglist" size="large" />
</group>
<group id="group1" label="Genderize">
<gallery id="gallery1" onAction="gallery1_Click" label="Identified Genders" size="large" columns="2" rows="2" itemHeight="32" itemWidth="32">
<button id="btnIndividualSalutation" imageMso="SendCopyOptions" onAction="btnIndividualSalutation_Click" label="Insert Individual Salutation" />
<button id="btnGroupSalutation" imageMso="SendCopyOptions" onAction="btnGroupSalutation_Click" label="Insert Group Salutation" />
</gallery>
</group>
<group id="group2" label="User Preferences">
<checkBox id="chkAutoSaveToContacts" onAction="chkAutoSaveToContacts_Click" label="Autosave to Contacts" />
<checkBox id="chkAutoAddSalutation" onAction="chkAutoAddSalutation_Click" label="Autoadd Salutation" />
<checkBox id="chkGroupSalutation" onAction="chkGroupSalutation_Click" label="Group Salutation" />
<checkBox id="chkAutoComplete" onAction="chkAutoComplete_Click" label="Autocomplete Text" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>