[英]Change Button in Ribbon on Ribbon load
I created a custom Ribbon for an Outlook 2007 AppointmentItem. 我为Outlook 2007 AppointmentItem创建了一个自定义功能区。 The AppointmentItem can have a custom property.
AppointmentItem可以具有自定义属性。 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. 我在自定义功能区中尝试了_Load函数,但该按钮仍处于启用状态。 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? 我不知道怎么了,可能是
Globals.Ribbons[...].Ribbon1
不是当前的Ribbon吗? Or is there a ribbon_load_finish_method? 还是有Ribbon_load_finish_method?
I used VisualStudio 2010 and .Net 3.5 我使用了VisualStudio 2010和.Net 3.5
Thanks for your time! 谢谢你的时间!
Why go through all the rigamarole? 为什么要经历所有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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.