an introduction to the model-view-viewmodel pattern srsly? another mv* pattern?...
TRANSCRIPT
An Introduction to the Model-View-ViewModel
Pattern
An Introduction to the Model-View-ViewModel
Pattern
Srsly? Another MV* Pattern?
Srsly? Another MV* Pattern?
The Healthcare ApplicationThe Healthcare Application
Screenshot of WebStationScreenshot of WebStation
A More Complete DiagramA More Complete Diagram
ViewXAML, Code Behind
Unit TestsIntegration Tests
ViewModelProperties, Commands, View Logic
Bin
din
gs
Actio
ns
Model
Service Proxies
Web
Data
Events
Behavio
r
Emerging TechnologyEmerging Technology
We’re still trying to figure out the Best Practices
We’re still trying to figure out the Best Practices
Standing on the Shoulders of Giants
Standing on the Shoulders of GiantsMVCMVPPresenter Model
MVCMVPPresenter Model
Martin Fowler Josh Smith John GossmanSean Wildermuth
Martin Fowler Josh Smith John GossmanSean Wildermuth
NotifyPropertyChangedNotifyPropertyChanged
public interface INotifyPropertyChanged
{
event PropertyChangedEventHandler
PropertyChanged;
}
public interface INotifyPropertyChanged
{
event PropertyChangedEventHandler
PropertyChanged;
}
Command PatternCommand Patternpublic interface ICommand{ bool CanExecute(object param); void Execute(object param); event EventHandler CanExecuteChanged;}
public interface ICommand{ bool CanExecute(object param); void Execute(object param); event EventHandler CanExecuteChanged;}
public class DelegateCommand : ICommand{ public DelegateCommand( Action<object> command, Predicate<object> canExecute);}
public class DelegateCommand : ICommand{ public DelegateCommand( Action<object> command, Predicate<object> canExecute);}
Attached BehaviorsAttached Behaviors<TextBlock Foreground=“Red” Width=“200” Behaviors:Update.WhenTextChanged=“True”/><TextBlock Foreground=“Red” Width=“200” Behaviors:Update.WhenTextChanged=“True”/>
TextBlock
FontSize
Foreground
Width
…
TrimmingBehavior
MVVM GuidelinesMVVM Guidelines
1. Reduce or eliminate your code-behind
2. Bind all of your UI inputs/outputs to your ViewModel
3. Implement INotifyPropertyChanged on your ViewModel
4. Put your view behavior into the ViewModel
5. Do not put any view state into the model
6. Only bind to a model object if there is no view-specific info
7. When testing, treat ViewModel as the Real UI
8. Avoid events. Use commands instead
1. Reduce or eliminate your code-behind
2. Bind all of your UI inputs/outputs to your ViewModel
3. Implement INotifyPropertyChanged on your ViewModel
4. Put your view behavior into the ViewModel
5. Do not put any view state into the model
6. Only bind to a model object if there is no view-specific info
7. When testing, treat ViewModel as the Real UI
8. Avoid events. Use commands instead
Third Party SupportThird Party Support
PrismMVVM LightCaliburnSilverlight FX
PrismMVVM LightCaliburnSilverlight FX
Who Creates the ViewModel?Who Creates the ViewModel?
XAMLView ConstructorOther ViewModel
MarriageDependency Injection
XAMLView ConstructorOther ViewModel
MarriageDependency Injection
Silverlight [Unit|Integration|Functional] Testing
Silverlight [Unit|Integration|Functional] Testing
Nunit/MoqSilverlight UTWhiteTelerik WebAI
Nunit/MoqSilverlight UTWhiteTelerik WebAI
Contact InfoContact [email protected]://HouseOfBilz.comhttp://Twitter.com/BrianGenisio
OPEN SPACEShttp://speakerrate.com/briangenisio
[email protected]://HouseOfBilz.comhttp://Twitter.com/BrianGenisio
OPEN SPACEShttp://speakerrate.com/briangenisio