none
Ribbon control shares data when multiple word windows opened RRS feed

  • Question

  • Hi,

    I've created a word 2010 addin and added a custom ribbon for my application. This ribbon contains some drop down items which i want to maintain data for per document.

    But i get a weird behaviour where as if i open multiple document there is two word window opened displaying my ribbon. If i change the dropdown selection in window 1 this action get automatically replicated in window 2 when activated.

    Is there any way to restrict this behaviour? Any help on this much appreciated.

    Note: I've tried the in built font drpdown changing the item selection does not reflect in the second window, do i need to specify anything on the ribbon to maintain its own state per window??

    Thanks,


    • Changed type rpriyams Thursday, May 26, 2011 10:03 AM
    • Edited by rpriyams Thursday, May 26, 2011 1:05 PM
    Thursday, May 26, 2011 10:03 AM

Answers

  • This is an Add-in, I take it, and not a VSTO document?

    Yes, a Ribbon defined in an Add-in will be application-level and not document-specific. If you have to have the Ribbon reflect the status in a specific document, then you need to do a bit of work. You need to hook into some application-level events, such as DocumentChange. Use them to invalidate the Ribbon and the dynamic callbacks to evaluate which has become the current document and what the status of the controls should be.

    The general approach is described in this article on the Custom Task Pane http://msdn.microsoft.com/en-us/library/bb608620.aspx


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by rpriyams Tuesday, May 31, 2011 10:47 AM
    Thursday, May 26, 2011 10:48 AM
    Moderator

All replies

  • This is an Add-in, I take it, and not a VSTO document?

    Yes, a Ribbon defined in an Add-in will be application-level and not document-specific. If you have to have the Ribbon reflect the status in a specific document, then you need to do a bit of work. You need to hook into some application-level events, such as DocumentChange. Use them to invalidate the Ribbon and the dynamic callbacks to evaluate which has become the current document and what the status of the controls should be.

    The general approach is described in this article on the Custom Task Pane http://msdn.microsoft.com/en-us/library/bb608620.aspx


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by rpriyams Tuesday, May 31, 2011 10:47 AM
    Thursday, May 26, 2011 10:48 AM
    Moderator
  • Thanks Cindy,

    Yes the ribbon is defined in an add-in ( application level ). As you suggested i have created some custom xml part section to store document specific values (ie., to store my drop down selection value ) and then hook the document change event to reset the selection by reading the last selected value from the custom document properties stored in the XML.

    It works great!! but the coding looks messy :(. i wonder how the in built ribbon control that shows font dropdown selection is retaining the values per document. Are they doing the same thing ???

     

    Tuesday, May 31, 2011 10:53 AM
  • << i wonder how the in built ribbon control that shows font dropdown selection is retaining the values per document. Are they doing the same thing ???>>

    I don't know. I would expect so, but I don't actually know...


    Cindy Meister, VSTO/Word MVP
    Tuesday, May 31, 2011 6:17 PM
    Moderator