This is a migrated thread and some comments may be shown as answers.

Any way to make CommandBarSplitButton function like a toggle button?

5 Answers 150 Views
CommandBar
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 2
Adam asked on 31 Jan 2012, 02:30 PM
I've read over this forum post which has a potential solution for RadSplitButton, but I am struggling to apply this to a CommandBarSplitButton.  

Basically the behavior I need is:
-when any menu item in the split button is clicked, that item should become the default item AND the button should show a highlighted state like IsMouseOver = true
-when the action button is clicked while it is highlighted, it should un-highlight.  (Other "cancel" conditions can cause this as well)

I have tried setting IsMouseOver = true on about every element I could find in the hierarchy.  I'd prefer not to have to create a custom theme or change the background colors manually if possible.

We're using Q2 2011 SP1 on our way to Q3 2011.

Thanks,
Adam

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 02 Feb 2012, 12:01 PM
Hello Adam,

Thank you for writing.

If I understand correctly, you want to change only the appearance of the button when item is selected and when the action button is clicked. If so, please refer to the attached application, which demonstrates how to achieve the desired appearance. This approach is valid for both Q2 2011 SP 1 and Q3 2011 SP 1.

A bit off topic, I would like to remind you that your subscription package has expired, which means that you are not entitled to support services. I would highly recommend upgrading your license to the latest version in order to continue getting product updates and uninterrupted support services. Please contact sales@telerik.com or visit your account for your upgrading options. 

I hope that you find this information helpful.

Regards,
Stefan
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Adam
Top achievements
Rank 2
answered on 02 Feb 2012, 01:58 PM
Stefan,

Thanks for the reminder, we're going to be getting our support up to date (today if I can believe my boss!).

As for your solution, it wasn't quite what I needed but I think I do have a way to do what I was trying to do:

-DefaultItemChanged won't work because I need the actionButton click to also toggle the highlighting
-using the menuItem_click won't quite work because by definition the mouse is over the button when clicking on it and leaving the button will trigger the IsMouseOver = false automatically

To solve this, I use the Tag property to store the toggle state.  By subscribing to the mouseLeave event I can check the toggle state and reset IsMouseOver = true;

void commandBarSplitButton1_MouseLeave(object sender, EventArgs e)
{
    if (commandBarSplitButton1.Tag != null && (bool)commandBarSplitButton1.Tag)
        commandBarSplitButton1.IsMouseOver = true;
}
 
void item_Click(object sender, EventArgs e)
{
    RadMenuItem item = sender as RadMenuItem;
    if (commandBarSplitButton1.DefaultItem == item && commandBarSplitButton1.Tag != null && (bool)commandBarSplitButton1.Tag)
    {
        commandBarSplitButton1.IsMouseOver = false;
        commandBarSplitButton1.Tag = false;
    }
    else
    {
        commandBarSplitButton1.DefaultItem = item;
        commandBarSplitButton1.IsMouseOver = true;
        commandBarSplitButton1.Tag = true;
    }
}


There is one more small problem, I'm working with the Office2010Silver theme.  The CommandBarSplitButton IsMouseOver in this case just outlines the entire control.  It seems that the split button highlight effects for this theme are split between whether the mouse is over the Action button or the Arrow button.  However I can't find an ActionButton property on the button or in the element tree to simulate mouse over.  (I'm fine with just highlighting the ActionButton if it means I don't need a custom theme).

Thanks,
Adam
.
0
Accepted
Stefan
Telerik team
answered on 07 Feb 2012, 12:17 PM
Hello Adam,

Thank you for writing back with the additional details.

In this case I believe it will be easier to directly set the colors of the buttons. Attached you can find the modified version of the sample project. Please take a look at it and let me know how it works for you. Please note that the colors in the ToggleButton method are taken from the Office2010Silver theme as per your requirement. 

Regards,
Stefan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Adam
Top achievements
Rank 2
answered on 07 Feb 2012, 03:25 PM
Stefan,

Thanks for the approach, looks like that is the way to go.   I appreciate the help, you guys rock!

-Adam
0
Stefan
Telerik team
answered on 10 Feb 2012, 09:39 AM
Hello Adam,

I am glad that I could help. If you have any other questions, do not hesitate to contact us.
 
Greetings,
Stefan
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
CommandBar
Asked by
Adam
Top achievements
Rank 2
Answers by
Stefan
Telerik team
Adam
Top achievements
Rank 2
Share this question
or