1

I have a ListView and grouped items inside of it. User has different ways of navigating into the page, and according to the way he navigates, I wish to have a certain group in view when the page opens.

I tried setting these:

itemGridView.ScrollIntoView(....);
itemGridView.SelectedIndex = ....;
itemGridView.SelectedItem = ....;

where itemGridView is the name of the ListView, but none of that seems to work.

Any help appreciated, thanks.

Igor Ralic
  • 14,975
  • 4
  • 43
  • 51

1 Answers1

1

You could do some visual tree traversing to find the ScrollViewer that is part of the ListView template, find the group and scroll the ScrollViewer to the position of your group.

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
  • I'll give it a shot tomorrow. I was hoping for a simpler solution, but if a man has to traverse a visual tree, a man has to traverse a visual tree :D – Igor Ralic Jul 04 '12 at 20:46
  • WinRT XAML Toolkit should make it easy though. Just call var sv = itemGridView.GetFirstDescendantOfType(), then var groupView = sv.GetDescendantsOfType().Where(gv => gv.DataContext == yourGroupViewModel), then sv.ScrollIntoView(gv). Well unless it does not work of course... :) – Filip Skakun Jul 05 '12 at 07:28
  • Where and when would it be safe to look for descendants if everything is data bound? I tried in Loaded event handler of the page, but it seems that not all the groups have been created yet (for example, the list of descendants has 3 items, even though I have 5 groups etc.) – Igor Ralic Jul 05 '12 at 11:24
  • 1
    It might have 3 items instead of 5 if it is using a virtualized panel. You might need to try doing something like this to disable virtualization, otherwise - I am not sure what the visual tree might be... – Filip Skakun Jul 05 '12 at 12:39
  • Yap you were right, the stackpanel is virtualized and that's probably causing me troubles in traversing it. – Igor Ralic Jul 09 '12 at 12:03