RadSplitButton dropdown does not work if command is not enabled

1 Answer 15 Views
Buttons
Joe
Top achievements
Rank 2
Iron
Veteran
Iron
Joe asked on 27 Mar 2022, 03:04 AM

I am using RadSplitButton.  I want the drop-down to be enabled even if the command itself is not valid to execute.   Is this a valid use-case for this control?

My dropdown content is a list of items.  The RadSplitButton content shows the currently selected item.  The command operates on the currently selected item and can only be executed if it is valid for that item.   

But as soon as the command becomes invalid for the currently selected item, the entire RadSplitButton control becomes disabled.  So I am unable to use the dropdown to select a different item, for which it might be valid.

Am I trying to use this control in a manner for which it was not intended?

1 Answer, 1 is accepted

Sort by
0
Stenly
Telerik team
answered on 30 Mar 2022, 11:45 AM

Hello Joe,

The observed behavior is the expected one because the RadSplitButton class implements the ICommandSource interface. When the CanExecute method of the command returns false, the IsEnabled property of the element becomes false.

With this being said, the desired result could still be achieved,  and to do so, instead of setting the Command of the RadSplitButton button, you could retrieve the RadButton element that represents the button part and set its Command property. For example, this could be done in the Loaded event of the RadSplitButton control, by utilizing the ChildrenOfType extension method.

The following code snippet shows this suggestion's implementation:

private void RadRibbonSplitButton_Loaded(object sender, RoutedEventArgs e)
{
    var splitBtn = sender as RadRibbonSplitButton;

    var btnPart = splitBtn.ChildrenOfType<RadButton>().FirstOrDefault();

    if (btnPart != null)
    {
        btnPart.Command = new DelegateCommand(OnExecuted, CanExecute);
    }
}

I have attached a sample project, so, could you give it a try?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Buttons
Asked by
Joe
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Stenly
Telerik team
Share this question
or