1
votes

why is it that sometimes setting the ItemsSource property on a Pivot control calls the SelectionChanged event, and sometimes it doesn't?

myPivot.ItemsSource = (ObservableCollections)someList;

it seems when i'm launching the app fresh from the app list, if i set the ItemsSource, the SelectionChanged event is always called. however, if i navigate away, tombstone the app (hit the home button) and then navigate back (hit the back button) to the original page, even though ItemsSource is set, SelectionChanged is never raised.

1
Can you post the code where you're setting the PivotIndex upon return ? (Most likely your OnNavigatedTo method) - Claus Jørgensen
i do not bind Pivot.ItemsSource in OnNavigatedTo(...). In the constructor of MainPage.xaml.cs, i create a BackgroundWorker, load my data in DoWork and then bind the data in RunWorkerCompleted. - jake
I was talking about when you were setting the PivotIndex. - Claus Jørgensen
i never set the PivotIndex explicitly. i do a simple Pivot.ItemsSource = ObservableCollections<MyObject>. i noticed that when i did that, Pivot.SelectionChanged is raised. do you advise that i do that? also, i don't see a Pivot.PivotIndex property, did you mean Pivot.SeletectedItemIndex? - jake
i didn't find Pivot.PivotIndex, but i tinkered a bit with Pivot.SelectedIndex and Pivot.SelectedItem. i noticed that even if Pivot.SelectedIndex >= 0, Pivot.SelectedItem could still be null. i simply added if(Pivot.SelectedItem == null) Pivot.SelectedItem = _myList[0], and now SelectedChanged is raised. thanks for the hint. - jake

1 Answers

1
votes

The behaviour changed in Windows Phone 7.1 (Mango). Due to the new "fast resume" improvement, the pivot control now automatically persists the position, and thus you no longer need to persist the selected pivot.

And for the same reason, the SelectionChanged event is never called, as the selection never changed.

For Windows Phone 7.0 (NoDo) you need to set the Pivot.SelectedIndex upon return (Best done in the Pivot.Loaded event).