Reputation: 341
I'm using a XML ribbon for an Excel add-in with C#. I'm new at this so I hope I have not misunderstood how it works. I have a SplitButton containing a button and a menu. I'd like the menu to open up when clicking the button just like if I clicked the caret.
What I have in XML:
<splitButton id="_mySplitButton" size="large">
<button id="_mySplitButton__btn" onAction="ShowMenu"/>
<menu id="_mySplitButton__mnu">
<!-- buttons here -->
</menu>
</splitButton>
What I have in C#:
public void ShowMenu(IRibbonControl control)
{
// Open the dropdown here
RibbonButton button = control as RibbonButton; // --> null
}
Unfortunately, I have no idea how to get to the menu dropdown. I cannot cast the callback parameter, nor can I access the control programmatically, as I've seen on several posts. So I'm wondering, is there any way to achieve this?
Upvotes: 0
Views: 957
Reputation: 1264
An alternative is to use the gallery:
<gallery id="alignGallery"
label="Align"
imageMso="ObjectsAlignLeft"
size="large"
showItemLabel="true"
columns="1"
onAction="OnGalleryButtonClicked"
>
<item id="alignLeft" label="Align Left" imageMso="ObjectsAlignLeft"/>
<item id="alignCenter" label="Align Center" imageMso="ObjectsAlignCenter"/>
<item id="alignRight" label="Align Right" imageMso="ObjectsAlignRight"/>
</gallery>
public void OnGalleryButtonClicked(IRibbonControl control, string id, int index)
{
switch(id)
{
case "alignLeft":
MessageBox.Show("Align Left selected.");
break;
case "alignCenter":
MessageBox.Show("Align Center selected.");
break;
case "alignRight":
MessageBox.Show("Align Right selected.");
break;
}
}
Upvotes: 0
Reputation: 341
I ended up finding a solution: using menus instead of splitbuttons. The menu's / splitbutton's appearance is the same, but a menu will open itself upon hovering or clicking, which is what I needed.
Upvotes: 2