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

radSpiltButton: prevent dropdown from closing on enter

1 Answer 200 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
jen
Top achievements
Rank 1
jen asked on 19 Apr 2016, 06:01 PM

I have a radSpiltButton with a simple search form in the drop down content. When the user hits enter I want a button on that form to be triggered (isDefault=true), however the enter is closing the drop down content.  How can I keep the content open when the user hits enter?

 

There doesn't seem to be a cancelable DropDownClosing event that I can cancel, so I tried checking for the pressed key in the DropDownClosed event. If the key is the enter key then I try to re-open the drop down. I received an error: "Cannot reopen a popup in the closed event handler."

private void splt_Customer_DropDownClosed(object sender, RoutedEventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.Return))
            {
                splt_Customer.IsOpen = true;
              // Error: "Cannot reopen a popup in the closed event handler."
            }
        }

 

I can't re-open the drop down content once its been closed; so how do I prevent it from closing on enter in the first place?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 22 Apr 2016, 08:25 AM
Hello Jen,

The drop down is closed because there is an additional framework logic that applies for the IsDefault property based on the different focus scopes. In addition the drop down content of the split button is rendered in a Popup element which is placed in a different visual tree than the application. Currently, the Enter key executes the Click of the split part button of the RadSplitButton control because .

In order to achieve your requirement you can focus an element in the drop down content of the split button when it is opened. For example, the text input or the button itself. 
private void splitButton_DropDownOpened(object sender, RoutedEventArgs e)
{
    var content = this.splitButton.DropDownContent as FrameworkElement;
    var button = content.FindChildByType<Button>();
    button.Focus();
}

I will also share the approach from your support ticket on the same topic, because it might be useful for someone that experiencing the same behavior.
private void splt_Customer_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return || e.Key == Key.Enter)
    {
        e.Handled = true;
        Model.Seach(); //button execute
    }
}

Regards,
Martin
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
Buttons
Asked by
jen
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or