Any way to make CommandBarSplitButton function like a toggle button?

6 posts, 1 answers
  1. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 31 Jan 2012 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 02 Feb 2012 Link to this post

    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).

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 02 Feb 2012 Link to this post

    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
    .
  5. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 07 Feb 2012 Link to this post

    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 >>
  6. Adam
    Adam avatar
    89 posts
    Member since:
    Mar 2008

    Posted 07 Feb 2012 Link to this post

    Stefan,

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

    -Adam
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Feb 2012 Link to this post

    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 >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready