动态更改功能区标签
我已经为 Outlook 2010 加载项创建了 VSTO 功能区。当我以前使用设计器时,我能够动态更改功能区按钮的标签。我现在正在手动编码(XML/C#),并且似乎无法确定如何完成同样的事情。 XML 中的“标签”项似乎是静态的。
仅供参考 - 其背后的目的是为用户识别图库中的项目数量。
谢谢。
I've created a VSTO Ribbon for an Outlook 2010 add-in. When I previously used the designer, I was able to dynamically change the label of the ribbon button. I'm now coding this by hand (XML/C#) and can't seem to determine how to accomplish the same thing. The "label" item in the XML seems to be static.
FYI - the purpose behind this is to identify the number of items in the gallery for the user.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在元素上设置一个 getLabel 属性。该值是回调函数的名称,调用该函数以动态提供标签名称。您可以通过编程方式刷新 UI 以强制调用所有回调。
There is a getLabel attribute you can set on your element. The value is the name of a callback function which is called to provide the label name dynamically. You can programmatically refresh the UI to force all of your callbacks to be called.
这应该适用于使用 C# 的 excel 和 Outlook。
我将根据您的问题假设您可以创建大部分 xml 来将按钮放到功能区上,因此我将跳过该部分。您也没有提到什么样的事件应该更改标签按钮,因此我假设单击按钮将导致标签文本更改。
首先将按钮 xml 代码放置到位
创建一个类级别变量,功能区类中的所有方法都可以在构造函数之前访问该变量,然后在构造函数中设置该值。您还需要功能区 UI 类变量。当使用 xml 中的加载方法(例如 onLoad="Ribbon_Load")加载功能区时,应实例化此变量。
接下来,在功能区类中,您将需要两个类“YourUniqueId_Click”和“GetYourLabelText”。
当功能区最初加载到 Outlook 或 Excel 中时,“GetYourLabelText”方法将运行。由于类变量“_buttonClicked”在构造函数中设置为 false,因此按钮标签将以“Button is Off”开始。每次单击按钮时,“_buttonClicked”都会更改布尔状态,然后按钮会重置,再次调用“GetYourLabelText”方法。
This should work for excel and outlook using C#.
I'm going to assume based on your question that you can create the majority of the xml to get the button onto the ribbon, so I'll skip that part. You also didn't mention what kind of an event should change the label button, so I'm going to assume that clicking the button will cause the label text change.
First get the button xml code into place
Create a class level variable that will be accessible to all the methods in your ribbon class before the constructor, and then set the value in your constructor. You'll also need the ribbon UI class variable. This variable should be instantiated when the ribbon loads using a load method in the xml such as onLoad="Ribbon_Load".
Next in your ribbon class you'll need two classes "YourUniqueId_Click" and "GetYourLabelText".
The "GetYourLabelText" method will run when the ribbon is initially loaded in outlook or excel. Since the class variable "_buttonClicked" is set to false in the constructor, the button label will start off as "Button is Off". Each time the button is clicked the "_buttonClicked" changes boolean state then the button resets calling the "GetYourLabelText" method again.