开发者

Problem when addinag a RibbonLabel to the Ribbon in word 2007

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</Lab开发者_StackOverflow中文版elText>

      </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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜