5

I asked this question in a similar post but there have been significant updates since then, but still no results so I will try to re-ask the question with the updated information.

Basically I have a pivot view with 4 pivot items. If I create the scenario where I hit the windows key then rapidly press the back key my application will reopen without reconstructing (this is the expected outcome). The functionality of the application is there. I can press application bar buttons etc.

What doesn't work is the pivot items are frozen. If I was on Pivot item A and I press the start and back button quickly I come back to Pivot Item A. If I try to switch Pivot Items, the screen does not update, its "frozen" on Pivot Item A BUT the functionality of Pivot Item B is there. (I know this because the application bar Icons for Pivot Item B are now showing).

I have read many articles on proper tombstoning scenarios and how to approach this problem. My data IS being tombstoned correctly, and upon reactivation the tombstoned data works. No objects are null so I don't have any exceptions being thrown at me.

I check to see if I need to reload the Main ViewModel (I don't need to in this case so the UI elements being created initially are not being re created).

What does fix the problem however is if the application is reconstructed. Lets say I go to the marketplace from my app, let it finish loading and press back, My application will be refreshed and working fine since it properly deactivated and reconstructed istelf. I don't rely on constructors doing all the work so I am not missing any key elements not being set when they aren't fired in the windows/back button scenario.

Does anyone have any idea why my screen would not be updating?

constructor/loaded event/on navigated to event

    public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    }
    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        if (App.firstTimeLoading == true)
        {
            App.firstTimeLoading = false;
        }
        BuildApplicationBar();
    }

     protected override void OnNavigatedTo(NavigationEventArgs e)
    {
      this.DataContext = App.ViewModel;
        App.viewIdentifier = StringResource.MainPageView;

        if (!App.ViewModel.IsDataLoaded)
        {
            App.ViewModel.LoadData();                

            String bookTitle;
            App.Parser.appBookInfoDict.TryGetValue(CPlayerInventoryKeys.kInventoryKeyTitleShortTitle, out bookTitle);
            PivotBackground.Title = bookTitle.ToUpper();

            CreatePivotItems();
        }
        if (App.playerController.chapterPlayer.Source == null)
            App.restoreStateClass.RestoreState();

        //applies the proper background image
        if (App.isDarkTheme)
        {
            BitmapImage bitmapImage = new BitmapImage(new Uri(StringResource.PanoramaBlackImage, UriKind.Relative));
            BackgroundImage.ImageSource = bitmapImage;
            BackgroundImage.Opacity = .85;
        }
        else
        {
            BitmapImage bitmapImage = new BitmapImage(new Uri(StringResource.PanoramaWhiteImage, UriKind.Relative));
            BackgroundImage.ImageSource = bitmapImage;
            BackgroundImage.Opacity = .5;
        }

        if (App.firstTimeLoading == false && PivotBackground.SelectedItem != SuggestedPivotItem)
            BuildApplicationBar();
        else if (PivotBackground.SelectedItem == SuggestedPivotItem)
        {
            BuildMarketPlaceApplicationBar();
        }
        base.OnNavigatedTo(e);
    }
2
  • Have you got a complete repro you can share?
    – Matt Lacey
    Aug 2, 2011 at 9:23
  • I updated with some relavent code, still step by step debugging this though Aug 2, 2011 at 20:04

3 Answers 3

0

I found the answer. Since I had a media element open (play/paused) and I was implementing the "non tombstoned" method of hitting windows key and back button very quickly, the media element source was corrupt. Even though I reset this source, apparently it can be ignored and not function properly. All I had to do was add a line of code to the Application Deactivated handler.

    private void Application_Deactivated(object sender, DeactivatedEventArgs e)
    {
        App.MainAudioPlayer.Source = null; //(only showing line added)
    }
0

The behavior you are describing seems to be solely related to the way you are manipulating data internally and constructing your layout. I tested this both in the emulator and on a couple of physical devices, both producing normal output (even when bound to a view model).

Try creating a new Pivot-based application (without all your data - just using the default template) and see if the problem persists. Also worth mentioning - are you testing on a device or in the emulator?

17
  • Ill be trying some of the things we talked about last night. I do remember however even commenting out all of my view model bindings for the main page and the problem still persisted. Aug 2, 2011 at 16:47
  • Interesting, I have fixed the problem for one of my views which is good news! The weird part is for the main view. In the OnNavigatedTo Event I set a this.Loaded event and after it runs all the other functionality, it never hits the loaded event for the main view. Aug 2, 2011 at 17:54
  • Is the Loaded event actually wired?
    – Den
    Aug 2, 2011 at 17:58
  • Sorry, what do you mean by that? I set the loaded event to a new event in the OnNavigatedTo so that is set properly, it never hits it though Aug 2, 2011 at 18:08
  • 1
    I disabled all the calls to the application bar and moved everything to OnNavigatedTo but that wasn't the case. I am in the (very long) process of slowly adding bits and pieces of my framework to a new project. This should help me really nail down the culprit. Aug 2, 2011 at 22:15
0

Are you using transitions from the toolkit?
Are they defined in XAML?

If so that could be the issue. There's a bug which is fixed in the next version.
The solution for now is to remove the transitions or define them in code.

2
  • I am using transitions from the toolkit. For instance, RootFrame = new Microsoft.Phone.Controls.TransitionFrame(); And yes they are defined in xaml, ill see what removing them does right now Aug 2, 2011 at 21:09
  • I disabled the transitions and no change. Pivot Selection Change event fires but the screen is still stuck. Aug 2, 2011 at 21:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.