Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:18:13+00:00 2026-05-28T19:18:13+00:00

Basically I had created my application entirely using code behind and now I’m migrating

  • 0

Basically I had created my application entirely using code behind and now I’m migrating over to MVVM. One of the challenges that I’m facing is how to deal with ViewModels that are being persisted in memory.

For example in the first version of my app I knew once the user hit the back button on a certain page that the view would be discarded and that everything would be cleared, but when I started using the ViewModel and navigated to the page it was using the ViewModel that was created the previous time I navigated to the page (In other words the constructor wasn’t called).

Now is this the way it’s supposed to work? I would prefer that I recreate the ViewModel everytime I navigate forward and discard it everytime I hit back. But like I said this is new to me. Am I supposed to use the same viewmodel and somehow refresh the values so it doesn’t show old data?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:18:15+00:00Added an answer on May 28, 2026 at 7:18 pm

    Here’s how I clear the view model when the user leaves the page (this code is in the page’s xaml.cs) file:

    protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
            {
                if (e.NavigationMode == NavigationMode.Back)
                    ViewModelLocator.ClearDetailsViewModel();
    
                base.OnNavigatingFrom(e);
            }
    

    the implementation of ClearDetailsViewModel is like

    if (_detailsViewModelStatic == null) return;
     _detailsViewModelStatic.Cleanup();
    _detailsViewModelStatic = null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically this code was working fine before. I had some computer issues and
In school, one of my professors had created a 3D game (not just an
I have been using a lot Entity Framework in a MVVM WPF application recently
So basically the assignment was we had to create a doubly linked list that's
Basically, I'm trying to create an object of unique objects, a set. I had
Basically if I had a mysql table with columns: id, type, content, version. There
Basically I have some code to check a specific directory to see if an
The title explains all... I have this snippet of code in my application: String
I'm attempting to create a true mosaic application. At the moment I have one
I have a application, and had to create another .h and .m file. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.