Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

WPF/MVVM Quick Start Tutorial

, 10 Oct 2012
A quick example of MVVM in WPF
MvvmExample.zip
MvvmExample
Example1
Properties
Settings.settings
Example2
Properties
Settings.settings
Example3
Properties
Settings.settings
Example4
Properties
Settings.settings
Example5
Properties
Settings.settings
Example6
Properties
Settings.settings
MicroMvvm
Properties
MvvmExample.suo
<Window x:Class="Example4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Example4"
        Title="Example 4" Height="350" Width="525" SizeToContent="WidthAndHeight" ResizeMode="NoResize">
    <Window.DataContext>
        <!-- Declaratively create an instance of our SongViewModel -->
        <local:SongViewModel />
    </Window.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Menu Grid.Row="0" Grid.ColumnSpan="3">
            <MenuItem Header="Test">
                <MenuItem Header="Update Artist" Command="{Binding UpdateArtistName}" />
            </MenuItem>
        </Menu>
        <Label Grid.Column="0" Grid.Row="1" Content="Example 4 - micro framework" />
        <Label Grid.Column="0" Grid.Row="2" Content="Artist:  " />
        <Label Grid.Column="1" Grid.Row="2" Content="{Binding ArtistName}" />
        <Button Grid.Column="1" Grid.Row="3" Name="ButtonUpdateArtist" Content="Update Artist Name" Command="{Binding UpdateArtistName}" />
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Barry Lapthorn

United Kingdom United Kingdom
Jack of all trades.

| Advertise | Privacy | Mobile
Web04 | 2.8.140921.1 | Last Updated 10 Oct 2012
Article Copyright 2011 by Barry Lapthorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid