I wrote an app for Windows Phone 7, recently I\'ve upgraded it to Windows Phone 8 and I plan on adding some features. Unfortunately, I\'ve run into a problem immediately af
The Panorama control in WP8 has a known databinding bug. The symptoms of the bug are that SelectionChanged doesn't fire, SelectedIndex & SelectedItem aren't reliable and that back navigation into a page with Panorama resets the panorama selected item.
For example, the following code sample will never fire the MessageBox and SelectedIndex & SelectedItem won't indicate the correct expected values.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
this.DataContext = new ObservableCollection()
{
new Cow("Foo"),
new Cow("Bar"),
new Cow("Baz")
};
}
private void Panorama_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("Panorama_SelectionChanged_1: " + panorama.SelectedIndex);
}
public class Cow
{
public Cow(string name)
{
Name = name;
}
public string Name { get; set; }
}
One obvious fix will be to manually initialize PanoramaItems in code-behind.
Another solution would be to change our collection from typed to untyped, and add the following code snippet to our bounded data class. So let's change our code from ObservableCollection to ObservableCollection and add some code to the Cow class:
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
this.DataContext = new ObservableCollection
Now, when we run this code snippet we can see SelectionChanged fires as expected with the correct SelectedIndex values:
