I have written a simple C++ COM Office add-in that loads a ribbon XML definition and displays a simple ribbon tab. It features some buttons and a dropDown (combobox/droplist). I can handle button click events and combo selection change events like a charm.
Now I want to update ribbon UI accordi开发者_C百科ng to changes in the active document so that some buttons are disabled and some items added/removed from combobox.
I have searched up and down and could not find a way to control this. Am I missing something very obvious? How can I change button enabled state from anywhere in my code?
The way I've seen it done, using the Windows Ribbon control: the extra buttons must be specified in the XML markup, at design time. At runtime, you call SetModes()
to specify which sets of widgets gets displayed in the ribbon.
Like this:
<Application.Views>
<Ribbon>
<Ribbon.Tabs>
<Tab CommandName="cmdTabMain" ApplicationModes="0,1">
<Group CommandName="cmdGroupCommon"
SizeDefinition="ThreeButtons"
ApplicationModes="0,1">
<Button CommandName="cmdButtonNew" />
<Button CommandName="cmdButtonOpen" />
<Button CommandName="cmdButtonSave" />
</Group>
<Group CommandName="cmdGroupSimple"
SizeDefinition="TwoButtons"
ApplicationModes="0">
<Button CommandName="cmdButtonSwitchToAdvanced" />
<Button CommandName="cmdButtonDropA" />
</Group>
<Group CommandName="cmdGroupAdvanced"
SizeDefinition="FourButtons"
ApplicationModes="1">
<Button CommandName="cmdButtonSwitchToSimple" />
<Button CommandName="cmdButtonDropA" />
<Button CommandName="cmdButtonDropB" />
<Button CommandName="cmdButtonDropC" />
</Group>
</Tab>
</Ribbon.Tabs>
</Ribbon>
</Application.Views>
Then (in C# anyway) in the click handler, you do _ribbon.SetModes(1)
or _ribbon.SetModes(0)
.
精彩评论