Access to Ribbon Controls at Runtime

D

DTekW108

Background
I have created an application level Word Add-in for Word 2007 using Visual
Studio 2008 and VSTO. I first created it just using the Visual Designer in
Visual Studio 2008. Just drag & drop controls onto the ribbon and set their
properties. In this initial approach, I had full dynamic control over all
the ribbon control properties e.g. enable/disable of buttons and checkboxes
based on what a user was clicking on. This approach is really just a bunch
of event handlers. The problem was that it put all the controls in the
built-in "Add-Ins" tab. So I changed to the embedded XML resource file
approach so I have an XML file that now creates the same UI but in a separate
tab. The initial UI that loads is fine. But this new approach apparently
uses a callback mechanism.


The problem
How do I get dynamic access to the Ribbon controls? I want to be able to
programmatically enable/disable Ribbon controls at runtime based on what
control the user has clicked .... as I did in my first approach. I also want
to be able to "tick" a checkbox control or "untick" it based on what the user
has done. This seems like a fairly basic thing to want to do in a UI. What
am I missing here? Can this be done?

If anyone could point me in the right direction, I'd be most grateful!

Thanks in advance!
 
S

Scott McPhillips [MVP]

DTekW108 said:
Background
I have created an application level Word Add-in for Word 2007 using Visual
Studio 2008 and VSTO. I first created it just using the Visual Designer
in
Visual Studio 2008. Just drag & drop controls onto the ribbon and set
their
properties. In this initial approach, I had full dynamic control over all
the ribbon control properties e.g. enable/disable of buttons and
checkboxes
based on what a user was clicking on. This approach is really just a
bunch
of event handlers. The problem was that it put all the controls in the
built-in "Add-Ins" tab. So I changed to the embedded XML resource file
approach so I have an XML file that now creates the same UI but in a
separate
tab. The initial UI that loads is fine. But this new approach
apparently
uses a callback mechanism.


The problem
How do I get dynamic access to the Ribbon controls? I want to be able to
programmatically enable/disable Ribbon controls at runtime based on what
control the user has clicked .... as I did in my first approach. I also
want
to be able to "tick" a checkbox control or "untick" it based on what the
user
has done. This seems like a fairly basic thing to want to do in a UI.
What
am I missing here? Can this be done?

If anyone could point me in the right direction, I'd be most grateful!

Thanks in advance!

You call InvalidateControl. Then the control does a callback that lets you
set its state.
 
D

DTekW108

Thanks for the quick response Scott! After some fiddling, I believe that
you are correct.

Some additional information for those who might be reading this post:
1. It appears that the ONLY approach is callbacks....you can't cast or use
some other approach.
2. The other piece is that with the callbacks, the developer has to take
more responsibility for keeping track of the UI state with instance members.
So it is a bit more cumbersome but it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top