Change Button in Ribbon on Ribbon load
I created a custom Ribbon for an Outlook 2007 App开发者_运维知识库ointmentItem. The AppointmentItem can have a custom property. When the custom property is set, a button in the custom Ribbon should be disabled (by default it is enabled).
I tried the _Load function in my custom Ribbon, but the button is still enabled. I can debug it: the string is filled and the button will be disabled, but in the frontend nothing happens.
public partial class Ribbon1 {
[...]
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
if (myCustomProperty != "")
{
Globals.Ribbons[Globals.ThisAddIn.Application.ActiveInspector()]
.Ribbon1.buttonCollaborate.Enabled = false;
}
}
[...]
}
I don't know whats wrong, may be Globals.Ribbons[...].Ribbon1
is not the current Ribbon? Or is there a ribbon_load_finish_method?
I used VisualStudio 2010 and .Net 3.5
Thanks for your time!
Why go through all the rigamarole? I had to write something similar a while back (for a mail item, not appointment) that required a button to be set based on a registry entry. This was my approach. I'm not saying it's perfect, but it worked for me.
Here's a snippet from my (sloppy) code:
string taglineActive;
OLRegistryAddin buttonSet = new OLRegistryAddin(); // variable for reading the value of the registry key
UpdateBody msgBody = new UpdateBody(); // method for adding/removing tagline from the message
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
taglineActive = buttonSet.RegCurrentValue(); // retrieve the current registry value
if (taglineActive == "0")
{
// tagline is off for all messages
ActiveAllMessages.Checked = false; // uncheck "All Messages" button
ActiveAllMessages.Label = "Inactive - All Messages"; // change the label
ActiveThisMessage.Visible = false; // hide the "This Message" button
ActiveThisMessage.Enabled = false; // deactivate the "This Message" button
}
else if (taglineActive == "1")
{
// tagline is on for all messages
ActiveAllMessages.Checked = true; // check "All Messages" button
ActiveAllMessages.Label = "Active - All Messages"; // change the label
ActiveThisMessage.Visible = true; // show the "This Message" button
ActiveThisMessage.Enabled = true; // activate the "This Message" button
}
精彩评论