Adding Dynamic Buttons to the RibbonUI

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having trouble creating new controls on the Ribbon at Runtime.
Given the following sample scenario:

When a user opens a certain task - I want to replace the ribbon and add a
set of buttons based on that specific task.

The problem is the number of buttons being added is not fixed. So Task A
might have 3 buttons and Task B might have 5 buttons. Since the number of
buttons isn't fixed, I don't see a way to define the buttons ahead of time in
the RibbonX definition and use callbacks to update the content of each button.

So, I also looked at using the GetCustomUI call to change the XML that is
loaded, but this only called the first time Ribbon loads - even if I call
Invalidate, so it works for the first task that opens, but how do I update it
for the next task that opens?

Does anyone have a similar problem or a solution to adding the buttons to
the Ribbon in the C# code at runtime?
 
You certainly can define the maximum number of buttons in your XML with
getVisible and getEnabled callbacks and set the visibility and enabled
status of each button in the callbacks. I do that in some of my addins that
support the ribbon.

You can also use the dynamicMenu control, you can read about that in the
information about the ribbon on the MSDN site.
 
Hi Ken -

I am thinking that creating an excess of buttons and hiding them might be
the way to go. However, in my case, this is difficult because there is no
maximum number constraint on the system the AddIn will be based on. I will
have to look into this option a little more.

I have also looked into the dynamic menu option some as well. I was
wondering if there is a way to make the dynamic menu appear as a set of
buttons on the Ribbon, instead of in a context menu or a split button menu.
Is this possible? If so, that is definitely the way to go.

Thanks again for the help!
Marc Kapke
 
No, it's not possible. A dynamicMenu will always appear the same way.
 
Back
Top