0
votes

I'm working on an application where a user defines a the controls on a form and can set the tab index of any control. As each control is added to the Grid that comprises the viewable form area, the tab index is set to either 0 (default) or some user-defined tab index. Tabbing through the form works fine until the tabindex of one of the controls is changed at runtime(the index doesn't seem to matter.) After this, tabbing cycles only through some of the controls and in addition, the window menu items are now tab stops(they weren't prior to the tabindex change.) Also, the menu's tab properties aren't bound to any datacontext.

The control that's currently changed is a checkbox, but I'm unable to reproduce the behavior with a simplified layout, so any suggestions would help.

1
BTW - There's no TabControl just buttons, checkboxes, labels etc in a Grid.jchristof
You can't expect someone to help you solving the problem without posting your codemakc
from what i understand is that you have to keep the tab index of user created form in file and assign these tab indexes to all controls of user created form.YOusaFZai
yes, some tab indexes are assigned at compile or default. At run time, any of the tab indexes could be reassigned. The reassignment causes the table cycling to break and stick on a control - usually a control with a default or 0 index and usually tabbing with shift-tab (backward).jchristof

1 Answers

1
votes

Our "form pages" user controls invisible and beneath the current visible page were never disabled when new ones were pushed on the top. Therefore they were included in the tab indexing behavior causing unwanted side effects.

This helped me get to the bottom of the issue:

void InitializeFocusLogger() {
        //debug key logging to make focus bugs easier to track
        EventManager.RegisterClassHandler(
            typeof(UIElement),
            Keyboard.PreviewGotKeyboardFocusEvent,
            (KeyboardFocusChangedEventHandler)OnPreviewGotKeyboardFocus);
}

string lastID = string.Empty;
private void OnPreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)         {
    FrameworkElement control = e.NewFocus as FrameworkElement;
    if (control == null) return;

    ControlViewModel controlVM = control.DataContext as ControlViewModel;

    if (controlVM == null || lastID == controlVM.ID) return;

    lastID = controlVM.ID;

    Debug.Print("Focused: {0} TabIndex: {1}", controlVM.ID, controlVM.TabIndex);
}