Hello,
We are currently struggling with tabbing in the XamPropertyGrid:
Provided a minimal example at the bottom.
Steps to reproduce:
Expected behavior: Editor is focused and the text is selected (case 1).
Actual behaviors:
We currently use version 20.1.9 productive, but I was able to reproduce the problem in the minimal example with version v21.1.27.
Sample application:
Tabbehavior_SampleApp.zip
Thanks in advance,
Hello Tomas,
I am attaching an expanded version of the previous modified sample project that appears to prevent the StackPanel focusing. There are a few added event handlers here.
I have added the EditModeEnded event on the XamTextEditor. In the EditModeStarted, the owning StackPanel is set to be Focusable = false. This is reset in EditModeEnded so that the normal tab behavior can continue.
The PreviewKeyDown and PreviewKeyUp events are now handled on the XamPropertyGrid as well. If the Keyboard.FocusedElement is a PropertyGridPropertyItemView and that PropertyGridPropertyItemView.EditorElement is a StackPanel, the Focusable property is set to false in PreviewKeyDown if the Shift key was pressed, and it is set back to true if the Shift key is released in PreviewKeyUp.
The above creates another potential scenario in that the Shift key may not have been released. To handle this, I have written a Style for PropertyGridPropertyItemView that handles the PreviewLostKeyboardFocus event and checks the EditorElement for a StackPanel and sets the Focusable property back to true as a fallback.
I am attaching the modified sample project to this post. Please let me know if you have any other questions or concerns on this matter.
4571.Tabbehavior_SampleApp.zip
Hi Andrew,
Thank you for your answer. Your solutions for both problems work well in our application except for one detail. By setting the Stackpanels/Grids property Focusable to true I face the problem that when I press shift+tab I first select the grid and only then I can move in the previous editor.
I modified the minimal example accordingly. Tabbehavior_SampleApp_New.zip
How can I make it so that it immediately selects the upper editor value without disabling the focusable property on the panel, since I need the Stackpanel to remain focusable so that the tabbing works in the first place?
I have been investigating into the behaviors you are describing and the behaviors you are looking to achieve, and I have some information for you on this matter.
After looking at your sample project, I see that many of the elements within the editor definitions in your XamPropertyGrid have the IsTabStop property set. This will have no effect, as we are handling the Tab press internal to the XamPropertyGrid to push the keyboard focus from editor to editor.
The reason that the XamTextEditor inside of the StackPanel is not being focused in this case is because when an EditorDefinition is focused from our internal handling of the Tab press, we essentially focus the first element within the EditorDefinition, as there is nothing we can do to ensure that the first element will be an editor or something along those lines – you can literally put anything you want in the EditTemplate for your PropertyGridEditorDefinition.
In order to work around this, I would recommend setting the Focusable property on your StackPanel to true, as it will be false by default. I have found that handling the PreviewGotKeyboardFocus event appears to work well to catch the tab navigation and attempted focusing of the StackPanel. In this event, you can focus the XamTextEditor that you have placed inside. Please note that I would recommend that you unhook the event prior to focusing the XamTextEditor and then re-hooking it after focusing, as not doing this appears to cause an infinite loop.
Regarding the select all behavior, this can be done in your sample project by using a Style for XamTextEditor and hooking the EditModeStarted event using an EventSetter. In that event’s handler, you can cast the sender to the XamTextEditor and invoke its SelectAll() method.
I am attaching a modified version of the sample project you originally provided to demonstrate the above.
Please let me know if you have any other questions or concerns on this matter.
7356.Tabbehavior_SampleApp.zip