views:

300

answers:

3

I am using VSTO 3.0 and the ribbon designer gives me a ribbon that is apparently shared across documents.

So if I have Document specific state( number of XML marked up tags say) that needs to show up in the ribbon( or a toggle button ) then all documents seem to share the ribbon instance

How can I fix this TIA

+2  A: 

Hook into an appropriate event (such as when the active document is changed) within the document model, and in that event invalidate the appropriate ribbon button (you'll need the id of the element from the original Ribbon xml you load).

Then, when the refresh state callback for that button occurs, you can update the caption/image/enabled as required.

Bevan
A: 

Bevan thanks

so if I do this and I have two documents up on two seperate monitors what will I see different on both docs? differing ribbons?

and specifically in my example where a label for example is showing the number of marked up xml tags in a document how will updating this label in both documents make sure that they show differnet values

Thanks

Rahul
The ribbon has separate state for each window - you can see this by opening two different Word 2007 windows on different documents. What you'll need to handle in your callback is accessing the appropriate document for the current window.
Bevan
+2  A: 

You can use Application.DocumentChange event or Application.WindowActivate event.

The first is fired then you change the current active document, but in the arguments there's no information about that document, so it's difficult to work with because you'll have to figure that out.

The latter is similar and it's fired every time you change of window but in this case it passes the current active document as an argument, so it's easier to change the ribbon if you need to check the value of any document property. That worked for me.

Marc Climent