by Corrado Cavalli via Corrado's BLogs on 9/27/2010 7:12:27 PM
The Panorama control is certainly one of the most interesting controls available on Windows Phone 7 toolset, unfortunately it has a defect that is evident during Tombstoning or when you navigate to a page containing a Panorama and try to set its initial view to an item other than the first one. To better understand what the problem is, let’s start with this page:
that has following code associated in order to properly handle its tombstoning:
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e){ base.OnNavigatedFrom(e); this.State["InitialIndex"] = MyPano.SelectedIndex;}protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){ base.OnNavigatedTo(e); if (this.State.ContainsKey("InitialIndex")) { MyPano.DefaultItem = MyPano.Items[(int)this.State["InitialIndex"]]; this.State.Remove("InitialIndex"); }}
Let’s now cause application deactivation by pressing the Tombstone button that invokes a SearchTask:
Enter SmartPanorama: A control derived from Panorama that adds a InitialIndex property through which you can easily restore initial position. The code for a correct restoring becomes:
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e){ base.OnNavigatedFrom(e); this.State["InitialIndex"] = MyPano.SelectedIndex;}protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e){ base.OnNavigatedTo(e); if (this.State.ContainsKey("InitialIndex")) { MyPano.InitialIndex = (int)this.State["InitialIndex"]; this.State.Remove("InitialIndex"); }}
Source code is available here so I won’t go into details, just a few clarifications:
As always: The software is provided “as is”, without any warranty.
Enjoy a “smarter panoraming”
Original Post: SmartPanorama: A Panorama control extension
The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.