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 8561561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:31:39+00:00 2026-06-11T16:31:39+00:00

I have a question: Where is the best place to create the ViewModel in

  • 0

I have a question: Where is the best place to create the ViewModel in MVVM and how?

1) Create once in App.xaml.cs as static field and then use it through App?

2) Alway create new ViewModel in Page.cs, when I navigate to this page?

3) other options

  • 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-06-11T16:31:40+00:00Added an answer on June 11, 2026 at 4:31 pm

    In MVVM, the ViewModel is the application. This means that I usually have an single startup ViewModel that is the entry point to my application, and I typically create an instance of this in the App.xaml.cs OnStartup code

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
    
        var app = new ShellView();
        var context = new ShellViewModel();
        app.DataContext = context;
        app.Show();
    }
    

    Every once in a while I have an application that will create the ViewModel in the startup window’s constructor, but this is not really preferred because it means if I have any startup logic, I have to put that in the code-behind the View as well, and I don’t like mixing application logic in my View layer.

    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new ShellViewModel();
        }
    }
    

    Regardless of how you do it, keep in mind that when using MVVM, your ViewModels are your application, not your Views, so typically your ViewModels are connected in some way to the startup ViewModel. Views are just a user-friendly way for users to interact with your application (the ViewModels).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about best practices in Java. I'm writing a class, which
I have a question regarding best-practice when including headers. Obviously include guards protect us
So I have a question of best practice in terms of extending functionality of
I have a question regarding the best practise of handling formated text when using
Simple question on best practice. Say I have: public class Product { public string
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',
I have a question about the proper, best way to manage the model. I
I have a best practice question. I'm developing a OO MVC framework in PHP,
I have a design/best practice question relating to MVC3. I have a front page
I have a UI question that troubled me on the best method to handle

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.