Reputation: 33089
This is a similar question to that posed in How to control the scroll position of a ListBox in a MVVM WPF app but, instead, I'm trying to achieve a similar effect from within a Windows Store app: I would like to know how to scroll a ListView
to the current (or an arbitrary) item from the view model in an MVVM-style app.
There are a couple of limitations in WinRT when compared to WPF:
IsSynchronizedWithCurrentItem
property is not supported on ListView
or related classes (the property exists but using it throws a runtime exception indicating that it is not currently supported);ICollectionView
, CollectionViewSource
and other related types.Fortunately, the CollectionViewSource
problem is elegantly solved by Bernardo Castilho's solution at CodeProject (http://www.codeproject.com/Articles/527686/A-WinRT-CollectionView-class-with-Filtering-and-So). Unfortunately, the lack of support for IsSynchronizedWithCurrentItem
makes solving the remainder of the problem tricky.
There are already several similar questions (e.g. Windows 8 Metro style ListView auto scroll) but they don't address the problem from an MVVM perspective and don't allow me to maintain a clean MVVM architecture with a minimum of code-behind in my project.
Upvotes: 1
Views: 3100
Reputation: 31724
You can check ListViewExtensions.ItemToBringIntoView
attached property from the WinRT XAML Toolkit, which should work similar to how you would bind the SelectedItem
property but it will bring an item into view instead.
Upvotes: 1