Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
820
Focus field values problem with keyboard Tab keypress
posted

Hello,

 

We are currently struggling with tabbing in the XamPropertyGrid:

  1. As soon as we use the TargetType or the TemplateSelector at the PropertyGridEditorDefinition it does not select the text when tabbing into the next editor field.
  2. If we use the TargetType or TemplateSelector in conjunction with a Grid or a Stackpanel in the Datatemplate we are not able to tab into the editor field at all.

 Provided a minimal example at the bottom.

Steps to reproduce:

  • Start the example application
  • Left click into the first editor field
  • Press TAB through the lines
  • + 2. Line: with TargetType + templateSelector -> Editor field is focused, but text is not selected (case 2)
  • Line: with TargetType + Stackpanel -> Editor field is not focused (case 3)
  • Line: with TargetType -> Editor field is focused, but text is not selected (case 2)
  • Line: with TargetType + Grid -> Editor field is not focused (case 3)

 

Expected behavior: Editor is focused and the text is selected (case 1).

Actual behaviors:

  • Editor is focused, but the text is not selected (case 2).

  • Next row is active, but to edit the editor needs to be focused manually (case 3).

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,

Parents
  • 33390
    Offline posted

    Hello Tomas,

    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

  • 820
    Offline posted in reply to Andrew Goldenbaum

    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

     Steps to reproduce:

    • Start the application
    • Select the lower editor field
    • Press shift+tab

    • Press shift+tab again

    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?

    Thanks in advance,

Reply Children
No Data