SlideShare a Scribd company logo
Software Architecture Pattern
M-V-VM
(Model-View-ViewModel)
Friday, July 26, 2013
View
ViewModel
Commands
Data
Binding
Model
Mvvmintroduction 130725124207-phpapp01
Model
public class Person
{
public Person() { }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Age { get; set; }
}
ViewModel
public class MainViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
ViewModel
private Person _selectedPerson;
public Person SelectedPerson
{
get { return _selectedPerson; }
set
{
if (_selectedPerson != value) {
_selectedPerson = value;
NotifyPropertyChanged("SelectedPerson");
}
}
}
View
<TextBox Text="{Binding FirstName, Mode=TwoWay}" />
View
<ListView
ItemsSource="{Binding ListOfPerson}"
SelectedItem="{Binding SelectedPerson, Mode=TwoWay}" />
View
ViewModel
Commands
Data
Binding
Model
• The Mode property determines how changes are synchronized
between the target control and data source
– OneTime – Control property is set once to the data value and any subsequent changes
are ignored
– OneWay – Changes in the data object are synchronized to the control property, but
changes in the control are not synchronized back to the data object
– TwoWay – Changes in the data object are synchronized to the control property and vice-
versa
<TextBlock x:Name="FirstName"
Text="{Binding FirstName, Mode=OneWay}"/>
• ViewModels implement INotifyPropertyChanged
public class ProfileViewModel : INotifyPropertyChanged
{
private Person _person;
public Person Person
{
get { return _person; }
set {
if (value != _person)
{
_person = value;
NotifyPropertyChanged("Person");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (null != PropertyChanged)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
<Button Command="{Binding EditCommand}"
CommandParameter="{Binding SelectedPerson}"
Content="Edit" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
class EditPersonCommand : ICommand
{
ViewModel _viewModel;
public EditPersonCommand(ViewModel viewModel)
{
_viewModel = viewModel;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object person)
{
_viewModel.EditPerson(person as Person);
}
}
• Reuse Model and View-Model code
• Test the ViewModel with unit tests
• Maintainability
• Can show design-time data in Expression
Blend and the Visual Studio designer
http://caliburnmicro.codeplex.com/http://mvvmlight.codeplex.com/
Rob EisenbergLaurent Bugnion
http://msdn.microsoft.com/en-us/library/gg405484%28v=pandp.40%29.aspx
http://msdn.microsoft.com/en-us/magazine/jj651572.aspx
Software Architecture Design
M-V-VM
(Model-View-ViewModel)
18/07/2013

More Related Content

PPTX
Knockout js
LearningTech
 
PPTX
Présentation et bonnes pratiques du pattern MVVM - MIC Belgique
Denis Voituron
 
PDF
Databinding and Performance-Tuning in Angular 2
Manfred Steyer
 
PDF
Windows 8 Training Fundamental - 1
Kevin Octavian
 
PDF
Getting Started with JavaScript
Kevin Hoyt
 
PPTX
How my team is applying JS framework for PHP projects.
Damon Hung Tran
 
PDF
Жизненный цикл React приложений
GDG Odessa
 
PDF
Android Jetpack: ViewModel and Testing
Yongjun Kim
 
Knockout js
LearningTech
 
Présentation et bonnes pratiques du pattern MVVM - MIC Belgique
Denis Voituron
 
Databinding and Performance-Tuning in Angular 2
Manfred Steyer
 
Windows 8 Training Fundamental - 1
Kevin Octavian
 
Getting Started with JavaScript
Kevin Hoyt
 
How my team is applying JS framework for PHP projects.
Damon Hung Tran
 
Жизненный цикл React приложений
GDG Odessa
 
Android Jetpack: ViewModel and Testing
Yongjun Kim
 

What's hot (12)

PDF
ReRxSwift
myposter GmbH
 
PPT
Grails Views
NexThoughts Technologies
 
PPTX
XAML Data Binding in UWP
Christian Hissibini
 
PPT
React.js 20150828
LearningTech
 
PPTX
Javascript 2
pavishkumarsingh
 
PPTX
Going with style: Themes and apps for Magento Go
X.commerce
 
PDF
Data binding в массы!
Artjoker
 
DOCX
Implement Search Screen Using Knockoutjs
Neeraj Kaushik
 
DOCX
บทที่3
Palm Unnop
 
PPTX
Web technology javascript
Uma mohan
 
PDF
Agile Data concept introduction
Romans Malinovskis
 
ReRxSwift
myposter GmbH
 
XAML Data Binding in UWP
Christian Hissibini
 
React.js 20150828
LearningTech
 
Javascript 2
pavishkumarsingh
 
Going with style: Themes and apps for Magento Go
X.commerce
 
Data binding в массы!
Artjoker
 
Implement Search Screen Using Knockoutjs
Neeraj Kaushik
 
บทที่3
Palm Unnop
 
Web technology javascript
Uma mohan
 
Agile Data concept introduction
Romans Malinovskis
 
Ad

Viewers also liked (6)

PPS
The brightredhat
DanasSlideshares
 
PPT
В этот светлый праздник Победы
biblioteka244
 
PPT
город чудный, город древний...
biblioteka244
 
DOC
21 ld qd-59775
Tiến Thành Cao
 
PPTX
The power of 1 percent
Георги Димитров
 
DOC
1152 laws 23_1291554107
Tiến Thành Cao
 
The brightredhat
DanasSlideshares
 
В этот светлый праздник Победы
biblioteka244
 
город чудный, город древний...
biblioteka244
 
21 ld qd-59775
Tiến Thành Cao
 
The power of 1 percent
Георги Димитров
 
1152 laws 23_1291554107
Tiến Thành Cao
 
Ad

Similar to Mvvmintroduction 130725124207-phpapp01 (20)

KEY
SOLID Principles
Chris Weldon
 
PDF
Backbone Basics with Examples
Sergey Bolshchikov
 
PDF
Architecture components - IT Talk
Constantine Mars
 
PDF
Architecture Components
DataArt
 
PPTX
Data binding в массы! (1.2)
Yurii Kotov
 
PDF
Wicket 6
codepitbull
 
PPTX
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
DOC
Converting Db Schema Into Uml Classes
Kaniska Mandal
 
PDF
Михаил Анохин "Data binding 2.0"
Fwdays
 
PPTX
Test and profile your Windows Phone 8 App
Michele Capra
 
PDF
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
lakshmijewellery
 
ODP
Codemotion appengine
Ignacio Coloma
 
PDF
"Android Data Binding в массы" Михаил Анохин
Fwdays
 
PDF
Snapshot Testing @ CocoaheadsNL
Lars Lockefeer
 
PDF
Form認証で学ぶSpring Security入門
Ryosuke Uchitate
 
PDF
Clean Javascript
Ryunosuke SATO
 
PPTX
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Ali Parmaksiz
 
PPTX
Android Architecture Components
BurhanuddinRashid
 
DOC
Create a Customized GMF DnD Framework
Kaniska Mandal
 
PPT
Unit testing with mock libs
Valentin Kolesnikov
 
SOLID Principles
Chris Weldon
 
Backbone Basics with Examples
Sergey Bolshchikov
 
Architecture components - IT Talk
Constantine Mars
 
Architecture Components
DataArt
 
Data binding в массы! (1.2)
Yurii Kotov
 
Wicket 6
codepitbull
 
Implementing CQRS and Event Sourcing with RavenDB
Oren Eini
 
Converting Db Schema Into Uml Classes
Kaniska Mandal
 
Михаил Анохин "Data binding 2.0"
Fwdays
 
Test and profile your Windows Phone 8 App
Michele Capra
 
Create a Code that will add an Add, Edi, and Delete button to the GU.pdf
lakshmijewellery
 
Codemotion appengine
Ignacio Coloma
 
"Android Data Binding в массы" Михаил Анохин
Fwdays
 
Snapshot Testing @ CocoaheadsNL
Lars Lockefeer
 
Form認証で学ぶSpring Security入門
Ryosuke Uchitate
 
Clean Javascript
Ryunosuke SATO
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
Ali Parmaksiz
 
Android Architecture Components
BurhanuddinRashid
 
Create a Customized GMF DnD Framework
Kaniska Mandal
 
Unit testing with mock libs
Valentin Kolesnikov
 

Recently uploaded (20)

PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PDF
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
PDF
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
New Download MiniTool Partition Wizard Crack Latest Version 2025
imang66g
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
New Download FL Studio Crack Full Version [Latest 2025]
imang66g
 
Presentation about variables and constant.pptx
safalsingh810
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
Generating Union types w/ Static Analysis
K. Matthew Dupree
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Summary Of Odoo 18.1 to 18.4 : The Way For Odoo 19
CandidRoot Solutions Private Limited
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Download iTop VPN Free 6.1.0.5882 Crack Full Activated Pre Latest 2025
imang66g
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
10 posting ideas for community engagement with AI prompts
Pankaj Taneja
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 

Mvvmintroduction 130725124207-phpapp01