locked
GridView focus/selection behaviour

    Question

  • A am writing a WinRT application which utilises a Gridview to display some data.  The Gridview has a SelectionMode of Extended so that as the user navigates the grid with the cursor keys the selected item moves with them (plus I have multi-select functionality)

    The problem I'm experiencing is that if you navigate the grid using the cursor keys and have Ctrl pressed down, the selected item remains where is was and only the focus changes.  My DataTemplate doesn't show the focused item so it's quite confusing to the user.

    Is there anyway I can change this behaviour so that navigating the grid with Ctrl held down works in the same way as if it wasn't being held down?

    Wednesday, January 14, 2015 1:29 PM

Answers

  • My DataTemplate doesn't show the focused item so it's quite confusing to the user.
    Not denoting the focused item is an accessibility bug and will be quite confusing to keyboard users. You should definitely fix the template to identify the focused item
    Wednesday, January 14, 2015 11:32 PM
    Owner

All replies

  • The answer was quite simple in the end.  Just add a GotFocus handler like this one:

        private void SdxGridView_GotFocus(object sender, RoutedEventArgs e)
        {
          if (e.OriginalSource is GridViewItem && !((GridViewItem)e.OriginalSource).IsSelected)
          {
            SelectedItems.Clear();
            ((GridViewItem)e.OriginalSource).IsSelected = true;
          }
        }

    Wednesday, January 14, 2015 9:44 PM
  • My DataTemplate doesn't show the focused item so it's quite confusing to the user.
    Not denoting the focused item is an accessibility bug and will be quite confusing to keyboard users. You should definitely fix the template to identify the focused item
    Wednesday, January 14, 2015 11:32 PM
    Owner