Prism icon indicating copy to clipboard operation
Prism copied to clipboard

Set initial keyboard focus on PopupWindowAction

Open csxpjc opened this issue 9 years ago • 3 comments

Feature request: Provide a property on popup windows to set initial keyboard focus to the first element of the loaded control. This is to improve usability on popup windows so that users don't need to click or tab to the first control each time the popup window is opened - particularly useful when popup windows are being used to enter list items thereby necessitating the popup being opened multiple times by the user.

StackOverflow has a good generic answer for setting the initial keyboard focus to an element when the window is loaded.

I've tried out the necessary code change and included it below for your reference.

Changes to class Prism.Interactivity.PopupWindowAction: public static readonly DependencyProperty SetKeyboardFocusToFirstElementProperty = DependencyProperty.Register( "SetKeyboardFocusToFirstElement", typeof(bool), typeof(PopupWindowAction), new PropertyMetadata(null));

protected void Window_Loaded(object sender, RoutedEventArgs e) { var window = sender as Window; window?.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); }

In Invoke method: if (this.SetKeyboardFocusToFirstElement) { wrapperWindow.Loaded += Window_Loaded; }

csxpjc avatar Jan 16 '17 10:01 csxpjc

Thank you for the suggestion. Unfortunately, this is not something that we will be adding to Prism. This is the responsibility of the developer to control focus, and there are too many scenarios that must be considered to add such a feature. It's not a simple as give the first control focus. Luckily, this can be done very easily with attached properties and custom code to meet your needs exactly.

brianlagunas avatar Jan 16 '17 15:01 brianlagunas

I second the attached property method. Hook up the the IsVisibleChanged event and you are golden

AngusMcIntyre avatar Jan 18 '17 13:01 AngusMcIntyre

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 30 '20 19:01 lock[bot]