Pure MVVM WPF Application

To create a pure MVVM application using WPF, follow these steps after creating a new WPF Application in Visual Studio:

1. Open App.xaml and remove StartupUri=”MainWindow.xaml”.

2. Create a Folder Called ViewModels, and create a public class called MainViewModel.cs.


public class MainViewModel
{
public static MainWindow MainW { get; set; }

public void Initialize()
{
MainW = new MainWindow();
MainW.Closed += (s, e) => App.Current.Shutdown();
MainW.ShowDialog();
}
}

3. Open App.xaml.cs and add inside the class:


public partial class App : Application
{
public static MainViewModel MainVM { get; set; }

public App()
{
MainVM = new MainViewModel();
MainVM.Initialize();
}
}

And that’s the place to begin with an MVVM application, implementing all the interfaces and commands needed

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s