none
How to access Ribbons at runtime RRS feed

  • Question

  • Hi,

    I'm trying to create an addin for OneNote 2010. There is a Ribbon labelControl on the tab created by my addin, which displays some words. I want to change the words when OneNote is navigated away from current page.

    Up to now, I have got a way to track the navigate events from OneNote Application Interfaces. But I don't know how to access the labelControl at runtime.

    The labelControl is designed in an xml.

    I once tried to create the labelControl by code. But I failed because I cannot call  this.Factory.CreateRibbonLabel();

    I just want the words to be changed when navigating. If Ribbon labelControl cannot do this, what else can?

    Thanks in advance for your help.

    Monday, February 13, 2012 11:52 AM

Answers

  • Hi Ross

    I'm not familiar with working with the Ribbon in a OneNote add-in, but in principle it shouldn't be any different than for other applications...

    Do you have a code sheet with onAction procedures for your buttons? That would also be where GetImage (the callback assigned to loadImage) is located.

    In the <customUI> element you need to add the attribute onLoad. Assign to it the name of a procedure on this code sheet that should execute when the Ribbon is loaded. The customUi element would then look something like this:

    <customUI xmlns=http://schemas.microsoft.com/office/2006/01/customui loadImage="GetImage" onLoad="RibbonLoad" >

    where RibbonLoad is the name of the procedure on the code sheet for the Ribbon.

    On that code sheet you need to declare an object of the data type IRibbonUI at the class (global) level. In RibbonLoad you assign the Ribbon object described by your XML to that global object. Something like this:

    IRibbonUI myRibbon;
    public sub RibbonLoad(ribbon as IRibbonUI)
      myRibbon = ribbon
    End Sub

    Instantiating the myRibbon object with the loaded Ribbon make it possible for your code to address the Ribbon at any time, later in the OneNote session. you need this in order to tell the Ribbon when it needs to re-evaluate a dynamic setting, such as the getLabel attribute and its associated callback procedure.

    So, at some time during the OneNote session, you want to have the label change, based on some action or event. In the code for that action or event, you need to tell the Ribbon to re-evaluate the control in question, which is done using the InvaidateControl method:

    myRibbon.InvalidateControl("idOfControl")

    Invalidating the control will cause all the "get" attributes to execute their callbacks.

    You'll find this in the documentation at http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx in the section "Dynamically Updating the Ribbon UI".


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by Ross Gao Sunday, February 26, 2012 10:12 AM
    Monday, February 13, 2012 5:14 PM
    Moderator

All replies

  • Hi Ross

    I'm not familiar with working with the Ribbon in a OneNote add-in, but in principle it shouldn't be any different than for other applications...

    Do you have a code sheet with onAction procedures for your buttons? That would also be where GetImage (the callback assigned to loadImage) is located.

    In the <customUI> element you need to add the attribute onLoad. Assign to it the name of a procedure on this code sheet that should execute when the Ribbon is loaded. The customUi element would then look something like this:

    <customUI xmlns=http://schemas.microsoft.com/office/2006/01/customui loadImage="GetImage" onLoad="RibbonLoad" >

    where RibbonLoad is the name of the procedure on the code sheet for the Ribbon.

    On that code sheet you need to declare an object of the data type IRibbonUI at the class (global) level. In RibbonLoad you assign the Ribbon object described by your XML to that global object. Something like this:

    IRibbonUI myRibbon;
    public sub RibbonLoad(ribbon as IRibbonUI)
      myRibbon = ribbon
    End Sub

    Instantiating the myRibbon object with the loaded Ribbon make it possible for your code to address the Ribbon at any time, later in the OneNote session. you need this in order to tell the Ribbon when it needs to re-evaluate a dynamic setting, such as the getLabel attribute and its associated callback procedure.

    So, at some time during the OneNote session, you want to have the label change, based on some action or event. In the code for that action or event, you need to tell the Ribbon to re-evaluate the control in question, which is done using the InvaidateControl method:

    myRibbon.InvalidateControl("idOfControl")

    Invalidating the control will cause all the "get" attributes to execute their callbacks.

    You'll find this in the documentation at http://msdn.microsoft.com/en-us/library/aa338202(office.12).aspx in the section "Dynamically Updating the Ribbon UI".


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by Ross Gao Sunday, February 26, 2012 10:12 AM
    Monday, February 13, 2012 5:14 PM
    Moderator
  • HI Cindy,

    Thanks for your reply. I have done it according your answer and the key is onLoad="RibbonLoad".

    Sunday, February 26, 2012 10:18 AM