简体   繁体   中英

WP7 Listbox Automatic Scrolling Using MVVM

I have a ListBox that I've bound to a List of ordered times. When the ListBox loads I'd like to show the item that will be next at the top of the screen.

Is there a way to do this in WP7 using MVVM? I've looked around and there seems to be solutions for WPF but I can't seem to find any for WP7.

I can think of two ways of doing this:

  1. Implement an attached property that calls ScrollIntoView when the value changes (this method seems cleaner, but I'm not 100% sure it will work on WP7's Silverlight 3 runtime)
  2. Implement it as a Blend Bahavior that supports a bindable property (the ButtonCommand behavior in P&P's WP7 Guide has some trickery to achieve this on SL3) that calls ScrollIntoView when the bound value changes.

It's worth noting that ScrollIntoView only ensures the value is visible, not that it's at the top.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM