在 Word 2007 中将 RibbonLabel 添加到功能区时出现问题
目前我正在研究 Ms-Word 2007 Addin。这里我使用 xml 文件动态生成功能区标签。请找到附件中的 xml 代码。
<LabelGroup>
<GroupName>grpDocumentInformation</GroupName>
<GroupLabel>Document Information</GroupLabel>
<Labels>
<Label>
<LabelName>lblReferenceNo</LabelName>
<LabelText>Reference No:</LabelText>
</Label>
<Label>
<LabelName>lblReferenceType</LabelName>
<LabelText>Reference Type:</LabelText>
</Label>
<Label>
<LabelName>lblCreatedBy</LabelName>
<LabelText>Created By</LabelText>
</Label>
<Label>
<LabelName>lblDocumentType</LabelName>
<LabelText>Document Type:</LabelText>
</Label>
</Labels>
</LabelGroup><Groups>
I am getting this xml and my code follows like this:
XmlNodeList labelGroupsList = xmlDoc.DocumentElement.SelectNodes("//Groups/LabelGroup");
foreach(labelGroupsList 中的 XmlNode 组)
{
rGroup = new RibbonGroup();
rGroup.Name = group.SelectSingleNode("GroupName").InnerText;
rGroup.Label = group.SelectSingleNode("GroupLabel").InnerText;
XmlNodeList labelElements = group.SelectNodes("Labels");
foreach (XmlNode labelList in labelElements)
{
XmlNodeList labels = labelList.SelectNodes("Label");
foreach (XmlNode label in labels)
{
rLabel = new RibbonLabel();
rLabel.Name = label.SelectSingleNode("LabelName").InnerText;
rLabel.Label = label.SelectSingleNode("LabelText").InnerText;
rLabel.Enabled = true;
rLabel.ShowLabel = true;
***rGroup.Items.Add(rLabel);***
}
}
tab1.Groups.Add(rGroup);
}
当我将标签添加到组中时遇到问题。如果该行被注释,我将得到一个空组。
请帮我将标签添加到组中。
谢谢, KS 雷迪·普拉萨德。
Currently i am working on Ms-Word 2007 Addin. Here I am using an xml file to generate the Ribbon labels dynamically. Please find the attached xml code.
<LabelGroup>
<GroupName>grpDocumentInformation</GroupName>
<GroupLabel>Document Information</GroupLabel>
<Labels>
<Label>
<LabelName>lblReferenceNo</LabelName>
<LabelText>Reference No:</LabelText>
</Label>
<Label>
<LabelName>lblReferenceType</LabelName>
<LabelText>Reference Type:</LabelText>
</Label>
<Label>
<LabelName>lblCreatedBy</LabelName>
<LabelText>Created By</LabelText>
</Label>
<Label>
<LabelName>lblDocumentType</LabelName>
<LabelText>Document Type:</LabelText>
</Label>
</Labels>
</LabelGroup><Groups>
I am getting this xml and my code follows like this:
XmlNodeList labelGroupsList = xmlDoc.DocumentElement.SelectNodes("//Groups/LabelGroup");
foreach (XmlNode group in labelGroupsList)
{
rGroup = new RibbonGroup();
rGroup.Name = group.SelectSingleNode("GroupName").InnerText;
rGroup.Label = group.SelectSingleNode("GroupLabel").InnerText;
XmlNodeList labelElements = group.SelectNodes("Labels");
foreach (XmlNode labelList in labelElements)
{
XmlNodeList labels = labelList.SelectNodes("Label");
foreach (XmlNode label in labels)
{
rLabel = new RibbonLabel();
rLabel.Name = label.SelectSingleNode("LabelName").InnerText;
rLabel.Label = label.SelectSingleNode("LabelText").InnerText;
rLabel.Enabled = true;
rLabel.ShowLabel = true;
***rGroup.Items.Add(rLabel);***
}
}
tab1.Groups.Add(rGroup);
}
I am getting problem when i am adding the Label to the Group.if that line is commented, i will get an empty group.
Please help me adding the label to the group.
Thanks,
K.S. Reddi Prasad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
说实话,我认为你让事情变得比需要的要困难得多。
实际上,一旦定义控件并将其传递到 Word,您就无法“添加”控件,因此通常最好在 xml 或功能区中预先“预定义”您可能需要的所有控件设计师,然后隐藏/显示或禁用/启用适用的控件,因为Word中发生的事情。它确实简化了整个功能区创建过程。
To be honest, I think you're making it a lot harder than it needs to be.
Realistically, you can't "add" controls once they've been defined and passed off to Word, so it usually works best to "predefine" all the controls you're likely to need, up front, in your xml or the ribbon designer, then hide/show or disable/enable the applicable controls as things happen in word. It really simplifies the whole ribbon creation process.