none
Is there a way to access a Ribbon (XML) at run time? RRS feed

  • Question

  • Hi,

    I'm developing office outlook addin by using Ribbon XML, I need to change the images of my buttons dynamically and also hide/show or create new buttons at runtime. To do this I'm trying to get the access of my Ribbon control.I know that its possible if ribbon developed using Ribbon designer and it is available in Global. But I used Ribbon xml .... PLs help me out to get the My Ribbon ctrl which is designed by using Ribbon XML?

    Saturday, December 10, 2011 7:00 PM

Answers

  • Hi Chandu

    I'd probably start a new thread for these new questions (Designer vs. XML) and specify in it that this is for Outlook. Outlook is special, with it's various kinds of windows.

    But FWIW (2) cannot be done with the Ribbon Designer. The Designer was designed for Office 2007 and context menus were not part of the Ribbon at that time. In addition, the Designer is mainly for "simple" customizations (for people with little XML knowledge). At the time, MS was hoping to migrate developers away from VBA and into .NET languages and the Designer was supposed to assist in that process.

    In the last few years, it's become clear that the .NET languages are not going to be the last word in programming languages - at least not as far as Office is concerned. So I don't expect the RibbonDesigner to be extended. My advice would be to stick with Ribbon XML if you're already using it.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Chandu Rayudu Monday, December 12, 2011 4:52 PM
    Monday, December 12, 2011 3:55 PM
    Moderator
  • Hello,

    Note that the Ribbon designer is just a visual tool that generates a Ribbon XML. And Office retrieves the Ribbon XML only once whether it is supplied via the Ribbon Designer or in any other way. You cannot change this behavior. As Cindy pointed: your way is to have all controls pre-created. Then you can show/hide the controls; you cannot create a new control. The only control that provides some dynamism is the Dynamic Ribbon Menu. Have a look at it; if it doesn't suit you then there's no other control.

    The Ribbon designer is for simple things. For more advaced use, you have to create the Ribbon XML yourself.

    As to your other questions, please see this thread: Outlook 2010 Context Menu and Ribbon.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader
    • Marked as answer by Chandu Rayudu Monday, December 12, 2011 4:53 PM
    Monday, December 12, 2011 4:39 PM

All replies

  • Hi Chandu

    In your Ribbon XML that defines the controls you need to include the attributes that specify the callbacks required.  You're probably already familiar with the onAction callback executes code when a button is clicked? There are also callbacks for hiding/showing controls (the attribute is named "visible") and changing images ("getImage").

    You should find these listed in the three-part article about customizing the Ribbon in part 2, for each control. Part 3 contains the method signatures for the various programming languages.

    http://msdn.microsoft.com/en-us/library/aa338199(office.12).aspx

    In order to get the Ribbon to re-evaluate, which will trigger the callbacks for such attributes, you need to use the Ribbon.InvalidateControl("controlID") or the Ribbon.Invalidate method. The use of these is presented in part 1 of the article.


    Cindy Meister, VSTO/Word MVP
    Saturday, December 10, 2011 7:10 PM
    Moderator
  • Hi Cindy,

    Thanks for the quick response.

    So, When ever I want to change any ribbon control state (Image or visibility etc..) , I need to explicitly call Ribbon.InvalidateControl("controlID"). to get the callbacks rite.

    So here I have some business logic which runs in background thread, depends up on this I have to change the controls.

    1. Can I call Invalidate from a background thread?

    2. Is there any way to create a new button add it to the existing ribbon?

     

    Saturday, December 10, 2011 7:25 PM
  • Hi Chandu

    1. I don't know. As Office is STA, background threads are always a bit "tricky".

    2. No. All controls you plan to use in the Ribbon must already be present when the Ribbon is loaded. You can make them visible/not visible or enabled/not enabled.

    What would be possible is an additional add-in that your application loads/unloads on-demand. You could pass that a specific Ribbon XML as it loads...


    Cindy Meister, VSTO/Word MVP
    Sunday, December 11, 2011 6:36 AM
    Moderator
  • Hello,

    > 1. Can I call Invalidate from a background thread?

    All calls to an Office object model must be made in the main thread. Doing this in another thread usually produces problems that you cannot work around. Plus, no one can tell you what kind of problems you will get.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader
    Sunday, December 11, 2011 12:29 PM
  • Hi ,

    Thanks for the clarifications. I modified code to Invalidate the ribbon from the STA thread itself.

    Actually I'm trying to understand which is the best approach to develop a ribbon.

    Ribbon designer or Ribbon XML.

    I'm trying 2 things.

    1) Loading Multiple ribbons at runtime ( in read mail, calendar etc..)

    2) Creating context menus

    I'm able to achieve these 2 points by using Ribbon XML.

    Now I wanted to try with Ribbon Designer. So please guide me ...

    1) I have 3 ribbons, I need to display them in Main explorer, Read mail, calender.

    I have seen some sample in msdn to do this with ribbon designer. By overriding CreateRibbonExtensibilityObject() method  

    if (myCondition == true)
        {
            Ribbon1 tempRibbon =
    new Ribbon1();
            tempRibbon.tab1.ControlId.ControlIdType =
                Microsoft.Office.Tools.Ribbon.RibbonControlIdType.Office;
            tempRibbon.tab1.ControlId.OfficeId =
    "TabHome";
           
    return new Microsoft.Office.Tools.Ribbon.RibbonManager(
               
    new Microsoft.Office.Tools.Ribbon.OfficeRibbon[]
                    { tempRibbon });
        }


    But this method will be called only once when addin loads, if I want to display Ribbon2 in calendar new appointment then how can I achieve this with Designer approach?

    2) How to create Context menus with Ribbon Designer approach? 

    Thank You

     

    Monday, December 12, 2011 2:25 PM
  • Hi Chandu

    I'd probably start a new thread for these new questions (Designer vs. XML) and specify in it that this is for Outlook. Outlook is special, with it's various kinds of windows.

    But FWIW (2) cannot be done with the Ribbon Designer. The Designer was designed for Office 2007 and context menus were not part of the Ribbon at that time. In addition, the Designer is mainly for "simple" customizations (for people with little XML knowledge). At the time, MS was hoping to migrate developers away from VBA and into .NET languages and the Designer was supposed to assist in that process.

    In the last few years, it's become clear that the .NET languages are not going to be the last word in programming languages - at least not as far as Office is concerned. So I don't expect the RibbonDesigner to be extended. My advice would be to stick with Ribbon XML if you're already using it.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Chandu Rayudu Monday, December 12, 2011 4:52 PM
    Monday, December 12, 2011 3:55 PM
    Moderator
  • Thx Cindy, Now I got the clear picture abt the Ribbon Xml and Designer.

    I will go with Ribbon XML :-)

    But I request you to answer my previous question (1)  probably in a new thread....

    Thank You

     

     

    Monday, December 12, 2011 4:38 PM
  • Hello,

    Note that the Ribbon designer is just a visual tool that generates a Ribbon XML. And Office retrieves the Ribbon XML only once whether it is supplied via the Ribbon Designer or in any other way. You cannot change this behavior. As Cindy pointed: your way is to have all controls pre-created. Then you can show/hide the controls; you cannot create a new control. The only control that provides some dynamism is the Dynamic Ribbon Menu. Have a look at it; if it doesn't suit you then there's no other control.

    The Ribbon designer is for simple things. For more advaced use, you have to create the Ribbon XML yourself.

    As to your other questions, please see this thread: Outlook 2010 Context Menu and Ribbon.


    Regards from Belarus (GMT + 3),

    Andrei Smolin
    Add-in Express Team Leader
    • Marked as answer by Chandu Rayudu Monday, December 12, 2011 4:53 PM
    Monday, December 12, 2011 4:39 PM
  • Hi Chandu

    I'm not able to answer your question (1) as I'm not conversant with Outlook (except as an end-user). That's one reason I advised you to open a new discussion :-)


    Cindy Meister, VSTO/Word MVP
    Monday, December 12, 2011 4:48 PM
    Moderator