none
How to call getcustomUI method on runtime ? RRS feed

  • Question

  • Hi,

    I developed an Addin by implementing IExtensibility2 and IRibbonExtensibility. Here only on startup of word the GetCustomUI method is called and Ribbon is generated.

    But here I wanted to give different customUI xml with document open and create new event.

    How can I implement this ? Please help..

     

    Thanks

    Sameer Kamarudeen


    Thanks Sameer Kamarudeen
    Wednesday, September 7, 2011 9:58 PM

Answers

  • Hi Sameer

    In this case, it would probably be best to use a dynamicMenu type of element, rather than a static menu element in your Ribbon XML.

    Whenever you need to repopulate the menu (DocumentOpen, DocumentNew, DocumentChange events, for example) you need to call the Ribbon.InvalidateControl("dynamicMenuId") method, where "dynamicMenuId" is the id you assign to the dynamicMenu element.

    That will cause the control to re-evaluate, meaning it will trigger all the "get" callbacks. In this case, you need the callback getContent.  That has the method signature public string menu_getContent(control as Office.IRibbonControl)

    You need to return valid Ribbon XML that defines the menu structure you want to display. Basically, you need a string with the xml structure you'd type into your static Ribbon XML for the menu, and include the customui namespace in the top-level (menu) element.


    Cindy Meister, VSTO/Word MVP
    Thursday, September 8, 2011 3:00 PM
    Moderator

All replies

  • Hi Sameer

    The Ribbon was not designed to be used in the manner you describe. Once a Ribbon customization is loaded, that's it. All the controls you want to have must be in it at that time; you can change their visibility and whether they're enabled.

    I suspect there might be an alternate approach, but before I write out all my thoughts, it would help me to know a bit more about the business logic of what you hope to achieve?


    Cindy Meister, VSTO/Word MVP
    Thursday, September 8, 2011 8:41 AM
    Moderator
  • Hi Sameer,

    Cindy is right that you can not add or remove controls in Ribbon after the ribbon has been loaded. But you can use getVisible attribute to change the visible property when running Office.

    For more about his, you can read: http://msdn.microsoft.com/en-us/library/aa338199(v=office.12).aspx

    Another way to change Office Ribbon when running Office is using document-level ribbon customization. The kind of customization only apply to the associated document. When you switch window of documents, the ribbon also will change. This seems to satisfy your requirement, but as I have said, it is document-level customization...

    In addition, although we can't change ribbon after loaded, we can determine which ribbon to load when loading. For example, you have already created two ribbons (XML), in the CreateRibbonExtensibilityObject event, code this:

            protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
            {
                //change the conditions here as you want to
                if (this.Application.Version == "14.0")
                {
                    return new Ribbon1();
                }
                else
                {
                    return new Ribbon2();
                }        
            }
    
    I look forward to hearing of you.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 8, 2011 9:56 AM
    Moderator
  • Hi,

     Cindy is right, I understand that point. We can have only one xml with all controls and can make it visible or hide. That logic works for me.

     But how do I access a ribbon.. Might be dump question.. :( .

    What I am trying to do is.. there is 10 different items in a menu item.. But in initial stage i just wanted to show one item lets say "new" and rest of items wanted to display only after new document event happened.

     In new document function I can see the document object. But is that the commandbar object should use to access the ribbon items ? If so i can use that to hide and make it visible.

    Please suggest.


    Thanks Sameer Kamarudeen
    Thursday, September 8, 2011 1:57 PM
  • Hi Sameer

    In this case, it would probably be best to use a dynamicMenu type of element, rather than a static menu element in your Ribbon XML.

    Whenever you need to repopulate the menu (DocumentOpen, DocumentNew, DocumentChange events, for example) you need to call the Ribbon.InvalidateControl("dynamicMenuId") method, where "dynamicMenuId" is the id you assign to the dynamicMenu element.

    That will cause the control to re-evaluate, meaning it will trigger all the "get" callbacks. In this case, you need the callback getContent.  That has the method signature public string menu_getContent(control as Office.IRibbonControl)

    You need to return valid Ribbon XML that defines the menu structure you want to display. Basically, you need a string with the xml structure you'd type into your static Ribbon XML for the menu, and include the customui namespace in the top-level (menu) element.


    Cindy Meister, VSTO/Word MVP
    Thursday, September 8, 2011 3:00 PM
    Moderator
  • Cindy,

     Dynamic menu is a good option. I am able to figure it out.. But here the dynamic menu happen only one time with a document right. Is there a way to run every time when user select the main tab. I mean when ever they click on tag i need to run some condition and make some item visible and some item not.. ?

     


    Thanks Sameer Kamarudeen
    Thursday, September 8, 2011 4:43 PM
  • Calvin,

     

     GetVisible is a good option... Is that possible to run all the items come under main tab.. when ever user click on tab ?

     


    Thanks Sameer Kamarudeen
    Thursday, September 8, 2011 4:44 PM
  • Hi Sameer

    For this, I think you'd have to resort to the Ribbon Accessibility UI:

     http://msdn.microsoft.com/en-us/library/bb404170.aspx

     

    Unless there's some other Word application event you could monitor in order to trigger InvalidateControl(), possibly WindowSelectionChange. 


    Cindy Meister, VSTO/Word MVP
    Friday, September 9, 2011 9:07 AM
    Moderator
  • For this, I think you'd have to resort to the Ribbon Accessibility UI:

     http://msdn.microsoft.com/en-us/library/bb404170.aspx

     

    Agreed.

    And here is an sample for your reference:

    http://code.msdn.microsoft.com/CSOfficeRibbonAccessibility-cd7fe67f


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 9, 2011 10:30 AM
    Moderator
  • Cindy.. Can you help me some thing with my new issue... its here

    http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/09c57795-67d7-49bb-a5ad-a762503f8ecb

     


    Thanks Sameer Kamarudeen
    Friday, September 9, 2011 3:17 PM
  • Hi Sameer

    I usually answer it I have something to contribute. But it looks like Andrei is doing a good job, there...


    Cindy Meister, VSTO/Word MVP
    Friday, September 9, 2011 3:32 PM
    Moderator