n00b
n00b

Reputation: 6330

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.

Upvotes: 0

Views: 498

Answers (1)

Richard Szalay
Richard Szalay

Reputation: 84724

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.

Upvotes: 1

Related Questions