Maintaining state on back navigation with WP7

Jan 6, 2011 at 10:16 PM

Out of the box, the sample Windows phone data binding application supplied with the WP7 tools acts as expected when navigating back from the details to the mainpage with both scroll position and selected item being maintained.

This basic behaviour appears broken with CM (or more likely I'm doing something wrong). I created what I thought was the simplest possible example app to test with two pages, page1 and page2, with both associated VMs deriving from Conductor<>.Collection.OneActive and each having a single Name property. Both VMs are registered with SimpleContainer as RegisterPerRequest. Here's Page1ViewModel.

    public class Page1ViewModel : Conductor<PageTwoViewModel>.Collection.OneActive
        readonly INavigationService navigationService;

        public Page1ViewModel( INavigationService navigationService )
            this.navigationService = navigationService;

        protected override void OnInitialize()
            this.Items.Add( new PageTwoViewModel { Name = "1" } );
            this.Items.Add( new PageTwoViewModel { Name = "2" } );
            this.Items.Add( new PageTwoViewModel { Name = "3" } );
            this.Items.Add( new PageTwoViewModel { Name = "4" } );

        public override void ActivateItem( PageTwoViewModel item )
            navigationService.Navigate( new Uri"/PageTwo.xaml?Name=" + item.Name, UriKind.RelativeOrAbsolute ) );

This works fine in terms of forward navigation to page2 however navigating back renders an empty list in page1. Now an simple fix for that is to change the OnInitialize override to OnActivate fixes thats not a real fix. 
Even though CM checks if DataContext is null when binding models to views, the view is still re-initialised and it looks like any previous state is lost, i.e. scroll position, selecteditem,...
This feels like a fundamental issue so I'm assuming I'm missing something here otherwise the fix is probably pretty straightforward but I wanted to ask before looking closer at the CM navigation code.
Any help appreciated...
Jan 7, 2011 at 12:30 AM

Send me your sample application. robertheisenberg at hotmail dot com

I'll look into it.

Jan 10, 2011 at 2:00 PM

I have the same issue here, keen to see if there's a resolution.

Jan 10, 2011 at 2:39 PM

I need a simple sample that reproduces the problem. Send one to the address above and I will address the issue as quickly as I can.

Jan 10, 2011 at 3:26 PM

Hi Rob, I sent the sample as a zip file to the mail address you gave on same day. if you don't have it let me know and I'll resend.

Jan 10, 2011 at 3:35 PM

Yes. Please send it again. I have not received it yet.

Jan 10, 2011 at 3:35 PM

Or if you like, create an issue and attach the file.

Jan 10, 2011 at 8:48 PM

Issue created -