locked
ListView with VirtualizingStackPanel remembers scroll position

    Question

  • Hello.

    In store app I have a problem with ListView which ItemsPanel is VirtualizingStackPanel. I scrolled list to the middle, reset ListView::DataContext, items disappeared as expected, then I restore DataContext, new or the same set of data binded to ListView::ItemsSource but listview remembered its scrolling position. How to make it scroll to the top when ItemsSource change?


    <ListView ItemsSource="{Binding Items, Mode=TwoWay}">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
    </ListView>
    If i use ItemsStackPanel instead of VirtualizingStackPanel, there is no problem with auto scrolling to the top. But I can't use  ItemsStackPanel because it has problems with visualizing a huge number of items.

    Wednesday, February 04, 2015 7:39 PM

Answers