Introduction
“MVVM” stands for “Model-View-ViewModel”. Model basically initialize properties, attributes whatever you say, and “ViewModel” contains all data of your application. Finally, View represents actual representation of data in your screen. Basically Data Binding works between “ViewModel” and “View “layer, “View” requests command and “ViewModel” accept it and responses to the “View”. I’m not going to the complete theoretical knowledge. I will try to give you the basic idea what “MVVM” is.
Now, let’s get crack in the best practice in this super awesome architectural model.
Creating a New Project
Firstly, open up a new project and name it “MVVMEx” or whatever you want. Now, add three folders “Models”, “ViewModels” and “Views” one by one, like this.

Figure 1
It should look exactly like the following figure 2.

Figure 2
Adding a New Page
Now, in “Views” folder right click and add a new “Blank Page”, give it a name “AutoView”.

Figure 3
Changing the Starting Page
Now one more thing we’ve to do, is changing our starting page. For that, you’ve to go “app.xaml.cs” and change this line of code,
- if (rootFrame.Content == null)
- {
- // When the navigation stack isn't restored navigate to the first page,
- // configuring the new page by passing required information as a navigation
- // parameter
- rootFrame.Navigate(typeof(Views.AutoView), e.Arguments);
- }
Because, we’ve replaced our “MainPage.xaml” and added a new page “AutoView.xaml”.
Adding Classes
Now, similarly right click on the “Model” folder and add a new class named “Auto.cs”. Again right click on the “ViewModels” folder and add another class named “AutoViewModel.cs”. After setup, your Solution Explorer will look like the following figure 4.

Figure 4
Now we’ll modify our “AutoView.xaml” as follows.
Modifying “AutoView.xaml” Page
Setting up app title and information.
- <!-- Title Panel -->
- <StackPanel Grid.Row="0" Margin="19,0,0,0">
- <TextBlock Text="Learn With BD Devs" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0"/>
- <TextBlock Text="MVVM" Margin="0,-6.5,0,26.5" Style="{ThemeResource HeaderTextBlockStyle}" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
- </StackPanel>
Modifying main grid
- <!--TODO: Content should be placed within the following grid-->
- <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
- <TextBlock Height="50"
- HorizontalAlignment="Left"
- Margin="10,10,0,0"
- Name="manufacturerBlock"
- Text="{Binding manufacturer,Mode=OneWay}"
- VerticalAlignment="Top"
- Width="342" FontSize="24"/>
- <TextBlock Height="50"
- HorizontalAlignment="Left"
- Margin="10,65,0,0"
- Name="modelBlock"
- Text="{Binding model,Mode=OneWay}"
- VerticalAlignment="Top"
- Width="342" FontSize="24"/>
- <TextBlock Height="50"
- HorizontalAlignment="Left"
- Margin="10,120,0,0"
- Name="colorBlock"
- Text="{Binding color,Mode=OneWay}"
- VerticalAlignment="Top"
- Width="342" FontSize="24"/>
- <TextBlock Height="50"
- HorizontalAlignment="Left"
- Margin="10,175,0,0"
- x:Name="yearBlock"
- Text="{Binding year, Mode=OneWay}"
- VerticalAlignment="Top"
- Width="342" FontSize="24"/>
- </Grid>


Devanand KumarPosted Jun 6, 2022, 9:47 AM
This Sample Can Help me to follow MVVM Pattern in my uwp project. Thanks.
Umair JameelPosted May 16, 2016, 3:34 PM
What a great information. This article have helped me alot in making my app using mvvm pattern, thank you so much for this. I have found manual implementation of mvvm pattern as well right here http://www.top5solutions.com/mvvm-pattern-uwp-windows-10-apps/
James CroftPosted Nov 17, 2015, 4:37 AM
You should take a look at the MVVM light framework which provides a lot of help out-of-the-box for the MVVM pattern. A great share :)
Anish AnsariPosted Nov 15, 2015, 11:03 AM
Good one
Santhakumar MunuswamyPosted Nov 14, 2015, 3:59 AM
Good article