SlideShare a Scribd company logo
1 of 59
WPF with MVVM: From the Trenches
Brent Edwards Senior Consultant with Magenic BrentE@magenic.com @brentledwards brentedwards.net
Why ‘From the Trenches’?
What We Will Cover ,[object Object]
Cool WPF concepts
What is it?
Why is it cool?
How is it used?
Helpful tricks to make life easier
Useful tools that make debugging suck less
Develop sample app as we go,[object Object]
What is MVVM? Model Business logic Business Object View Presentation XAML View Model Functionality Model for the View
Why is MVVM Cool? Separates Presentation from Functionality Promotes testability Works great with Data Binding Easy collaboration with Designers No code-behinds
Cost of MVVM No built in IDE support All interactions must be manually wired up New and shiny, but fragmented Lots of different frameworks Lots of different opinions
Cool WPF Concepts
DataContext What is it? A way to give elements a scope for data binding Why is it cool? Makes it easy to bind controls Can be static or dynamic
DataContext How is it used? Statically OR
DataContext How is it used? Dynamically From code
Data Binding What is it? A way for applications to present and interact with data Why is it cool? Simple syntax to set up, WPF does the rest
Data Binding How is it used? Binding syntax in XAML Two Way (Default Behavior) Implement INotifyPropertyChanged on view model or business object
Commanding What is it? A way to bind commands to a DataContext Why is it cool? Can wire UI events to fire commands on View Model Can pass parameters via binding
Commanding How is it used? Expose ICommand property on View Model Assign a command to the property Prism’s DelegateCommand Bind to command in XAML
Commanding [Demo]
Data Templates What is it? A way to define the presentation of your data Why is it cool? Can give a ‘look’ to your business objects You can leverage data binding
Data Templates How is it used?
Data Templates [Demo]
Data Triggers What is it? Set style properties based on data values Why is it cool? Change presentation based on data properties
Data Triggers How is it used?
Data Triggers [Demo]
Value Converters What is it? Converts data value to format required by UI Why is it cool? Easy way to convert DateTime, Decimals, Integers or Booleans
Value Converters How is it used? Implement IValueConverter Convert, ConvertBack Include in Resources with a Key Use it!
Value Converters [Demo]
Data Template Selectors What is it? Select DataTemplate based on custom logic Why is it cool Select DataTemplate based on properties on view models or business objects Can be unit tested
Data Template Selectors How is it used? Inherit from DataTemplateSelector Add properties for the DataTemplates to select from Override SelectTemplate Add logic to actually select the template Add DataTemplates to XAML
Data Template Selectors How is it used? Add DataTemplateSelector to XAML Use it! ContentControl ListView ListBox
Data Template Selectors [Demo]
Helpful Tricks [To make life easier]
Event Aggregator / Message Bus What is it? Centralized location to route [Events | Messages] Why is it cool? Great way to decouple view models Makes testing a breeze
Event Aggregator / Message Bus How is it used? Use an IOC container Castle Windsor Implement as a Singleton Static property Important that all calls route through same instance Options Prism’s Event Aggregator Roll your own
Event Aggregator / Message Bus [Demo]
Navigation The Problem Views coupled with other Views View Models know about Views No separation of concerns No testability
Navigation A Solution Some Convention, Some Configuration Leverage [Event Aggregator | Message Bus] Leverage IOC Castle Windsor Leverage Reflection
Navigation Convention View Models all have default constructors View Models have an optional Load method with 0 or 1 argument(s)
Navigation Configuration – Key Players ViewTargets ViewConfiguration ViewController ViewResult ViewFactory ContainerConfiguration
Navigation Configuration - ViewTargets Enumerates the views which can be navigated to The glue that sticks everything together
Navigation Configuration - ViewConfiguration Pairs a View with an optional View Model Associated to a ViewTarget in the IOC Container
Navigation Configuration - ViewController The only object that interacts with the UI framework Listens for [Events | Messages] related to showing views Gives view details to ViewFactory to be built
Navigation Configuration – ViewFactory Resolves ViewConfiguration for the requested View Dynamically creates the View and View Model Loads the View Model with optional params using reflection Gives back a ViewResult
Navigation Configuration – ViewResult Result of the dynamic build process Has the built View along with any relevant data Used by ViewController to show the View
Navigation [Demo]
Modal Dialogs Problem Modal dialogs stall tests [MessageBox| OpenFileDialog| PrintDialog] How can you leverage these and keep view models testable?
Modal Dialogs Option 1 Wrap them up! Define interface IMessageShower Define implementation MessageShower Wire up with IOC Container Castle Windsor Test with mocks RhinoMocks
Modal Dialogs Option 2 [Event Aggregator | Message Bus] Create [Events | Messages] Create class listen for [Events | Messages] that get published Test by verifying [Events | Messages] are published Good for “Fire and Forget” Breaks down if results are returned
Modal Dialogs [Demo]
Magic with ContentControl The Problem Editable View and Read Only View Views have identical layout TextBox in for Editable Label for Read Only
Magic with ContentControl A Solution – ContentControl! DataTriggers Give different presentation depending on data values Works dynamically DataTemplateSelector Select which DataTemplate to use Only works when initially bound
Magic with ContentControl [Demo]
Useful Tools [To make debugging suck less]
Snoop Inspects visual tree Shows properties Shows events Can show 3D representation

More Related Content

What's hot

Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMDong-Ho Lee
 
MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)Yaroslav Voloshyn
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesQamar Abbas
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: AndroidJitendra Kumar
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009Jonas Follesø
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModelDareen Alhiyari
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 
Getting started with Xamarin forms
Getting started with Xamarin formsGetting started with Xamarin forms
Getting started with Xamarin formsSolTech, Inc.
 
Dev-In-Town: Ultimate Data Visualization by Walter Wong
Dev-In-Town: Ultimate Data Visualization by Walter WongDev-In-Town: Ultimate Data Visualization by Walter Wong
Dev-In-Town: Ultimate Data Visualization by Walter WongQuek Lilian
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPFS V
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightDevnology
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )Ahmed Emad
 
4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...
4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...
4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...PROIDEA
 
Difference between Software Architectural pattern
Difference between Software Architectural patternDifference between Software Architectural pattern
Difference between Software Architectural patternAnuj J Pandey
 
Building xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvmBuilding xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvmMike Melusky
 

What's hot (20)

Mvvm basics
Mvvm basicsMvvm basics
Mvvm basics
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
 
Slide Presentation of MVP Pattern Concept
Slide Presentation of MVP Pattern ConceptSlide Presentation of MVP Pattern Concept
Slide Presentation of MVP Pattern Concept
 
MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)MVx patterns in iOS (MVC, MVP, MVVM)
MVx patterns in iOS (MVC, MVP, MVVM)
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009MVVM Design Pattern NDC2009
MVVM Design Pattern NDC2009
 
MVVM - Model View ViewModel
MVVM - Model View ViewModelMVVM - Model View ViewModel
MVVM - Model View ViewModel
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
Getting started with Xamarin forms
Getting started with Xamarin formsGetting started with Xamarin forms
Getting started with Xamarin forms
 
Dev-In-Town: Ultimate Data Visualization by Walter Wong
Dev-In-Town: Ultimate Data Visualization by Walter WongDev-In-Town: Ultimate Data Visualization by Walter Wong
Dev-In-Town: Ultimate Data Visualization by Walter Wong
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 
No brainer
No brainerNo brainer
No brainer
 
MVC
MVCMVC
MVC
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in Silverlight
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )
 
4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...
4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...
4Developers 2015: Twoja własna profesjonalna kontrolka WPF - tak jak robią to...
 
Difference between Software Architectural pattern
Difference between Software Architectural patternDifference between Software Architectural pattern
Difference between Software Architectural pattern
 
Building xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvmBuilding xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvm
 

Viewers also liked

Du an can ho 4S Riverside Linh Dong
Du an can ho 4S Riverside Linh DongDu an can ho 4S Riverside Linh Dong
Du an can ho 4S Riverside Linh Dongdinhdk
 
Internet freedom
Internet freedomInternet freedom
Internet freedomsibiyanto
 
2008 DREAM Initiative Establishing A NPO
2008 DREAM Initiative Establishing A NPO2008 DREAM Initiative Establishing A NPO
2008 DREAM Initiative Establishing A NPOStephanie Lindley
 
Scdsb information and communication technology initiatives january 2011 final
Scdsb information and communication technology initiatives january 2011 finalScdsb information and communication technology initiatives january 2011 final
Scdsb information and communication technology initiatives january 2011 finaljaccalder
 
Online Marketing for Small Businesses
Online Marketing for Small BusinessesOnline Marketing for Small Businesses
Online Marketing for Small BusinessesAmy Black
 
2008 Non Profits Best Practices
2008 Non Profits Best Practices2008 Non Profits Best Practices
2008 Non Profits Best PracticesStephanie Lindley
 
HUERTO ECOLÓGICO EN EL COLEGIO
HUERTO ECOLÓGICO EN EL COLEGIO HUERTO ECOLÓGICO EN EL COLEGIO
HUERTO ECOLÓGICO EN EL COLEGIO tapialoli
 
20110528美国小企业管理局简介introduction of american small business administration
20110528美国小企业管理局简介introduction of american small business administration20110528美国小企业管理局简介introduction of american small business administration
20110528美国小企业管理局简介introduction of american small business administration宇 华
 
Allain behaviorism
Allain behaviorismAllain behaviorism
Allain behaviorismguest4917eb
 
Introduction to the Nutrition Program Design Assistant
Introduction to the Nutrition Program Design AssistantIntroduction to the Nutrition Program Design Assistant
Introduction to the Nutrition Program Design Assistantjehill3
 
2009 DREAM Construction Seminar Case Study - Silver Moon Plaza
2009 DREAM Construction Seminar Case Study - Silver Moon Plaza2009 DREAM Construction Seminar Case Study - Silver Moon Plaza
2009 DREAM Construction Seminar Case Study - Silver Moon PlazaStephanie Lindley
 
Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...
Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...
Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...Ellh
 
Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...
Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...
Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...jehill3
 
Presentation3
Presentation3Presentation3
Presentation3Darijiro
 
Mobile Marketing - mobiele ontwikkelingen en oplossingen
Mobile Marketing - mobiele ontwikkelingen en oplossingenMobile Marketing - mobiele ontwikkelingen en oplossingen
Mobile Marketing - mobiele ontwikkelingen en oplossingenWieger Waardenburg
 

Viewers also liked (20)

Introduzione WPF
Introduzione WPFIntroduzione WPF
Introduzione WPF
 
Du an can ho 4S Riverside Linh Dong
Du an can ho 4S Riverside Linh DongDu an can ho 4S Riverside Linh Dong
Du an can ho 4S Riverside Linh Dong
 
Internet freedom
Internet freedomInternet freedom
Internet freedom
 
Nz powerpoint
Nz powerpointNz powerpoint
Nz powerpoint
 
2008 DREAM Initiative Establishing A NPO
2008 DREAM Initiative Establishing A NPO2008 DREAM Initiative Establishing A NPO
2008 DREAM Initiative Establishing A NPO
 
Scdsb information and communication technology initiatives january 2011 final
Scdsb information and communication technology initiatives january 2011 finalScdsb information and communication technology initiatives january 2011 final
Scdsb information and communication technology initiatives january 2011 final
 
Online Marketing for Small Businesses
Online Marketing for Small BusinessesOnline Marketing for Small Businesses
Online Marketing for Small Businesses
 
2008 Non Profits Best Practices
2008 Non Profits Best Practices2008 Non Profits Best Practices
2008 Non Profits Best Practices
 
Studmco
StudmcoStudmco
Studmco
 
HUERTO ECOLÓGICO EN EL COLEGIO
HUERTO ECOLÓGICO EN EL COLEGIO HUERTO ECOLÓGICO EN EL COLEGIO
HUERTO ECOLÓGICO EN EL COLEGIO
 
20110528美国小企业管理局简介introduction of american small business administration
20110528美国小企业管理局简介introduction of american small business administration20110528美国小企业管理局简介introduction of american small business administration
20110528美国小企业管理局简介introduction of american small business administration
 
Administración de contenido
Administración de contenidoAdministración de contenido
Administración de contenido
 
Allain behaviorism
Allain behaviorismAllain behaviorism
Allain behaviorism
 
Introduction to the Nutrition Program Design Assistant
Introduction to the Nutrition Program Design AssistantIntroduction to the Nutrition Program Design Assistant
Introduction to the Nutrition Program Design Assistant
 
2009 DREAM Construction Seminar Case Study - Silver Moon Plaza
2009 DREAM Construction Seminar Case Study - Silver Moon Plaza2009 DREAM Construction Seminar Case Study - Silver Moon Plaza
2009 DREAM Construction Seminar Case Study - Silver Moon Plaza
 
Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...
Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...
Εκπαιδευτικά Σενάρια και εφαρμογές για το Νηπιαγωγείο με τη χρήση του Διαδικτ...
 
Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...
Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...
Maternal Anemia within Child Survival Grants Program:  Lessons Learned and a ...
 
Presentation3
Presentation3Presentation3
Presentation3
 
Mobile Marketing - mobiele ontwikkelingen en oplossingen
Mobile Marketing - mobiele ontwikkelingen en oplossingenMobile Marketing - mobiele ontwikkelingen en oplossingen
Mobile Marketing - mobiele ontwikkelingen en oplossingen
 
Velagroup
VelagroupVelagroup
Velagroup
 

Similar to WPF with MVVM: From the Trenches

Building an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernatebwullems
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10Bryan Anderson
 
Portable Class Libraries and MVVM
Portable Class Libraries and MVVMPortable Class Libraries and MVVM
Portable Class Libraries and MVVMAndreas Kuntner
 
Presentation Model
Presentation ModelPresentation Model
Presentation ModelAlex Miranda
 
Machine Learning & Amazon SageMaker
Machine Learning & Amazon SageMakerMachine Learning & Amazon SageMaker
Machine Learning & Amazon SageMakerAmazon Web Services
 
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
Mvc vs mvp vs mvvm  a guide on architecture presentation patternsMvc vs mvp vs mvvm  a guide on architecture presentation patterns
Mvc vs mvp vs mvvm a guide on architecture presentation patternsConcetto Labs
 
Mvvm pattern
Mvvm patternMvvm pattern
Mvvm patternmsarangam
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentationInova LLC
 
Deep Dive: MVC Controller Architecture
Deep Dive: MVC Controller ArchitectureDeep Dive: MVC Controller Architecture
Deep Dive: MVC Controller ArchitectureChris Eargle
 
MDA Vs Web Ratio for Non It
MDA Vs Web Ratio for Non ItMDA Vs Web Ratio for Non It
MDA Vs Web Ratio for Non Itanicolay
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0Shiju Varghese
 
PASSMN Summit 2009 Upgrade to SSAS 2008
PASSMN Summit 2009 Upgrade to SSAS 2008PASSMN Summit 2009 Upgrade to SSAS 2008
PASSMN Summit 2009 Upgrade to SSAS 2008Dan English
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patternseleksdev
 
A Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVMA Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVMChris Bannon
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCAnton Krasnoshchok
 
Cloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScriptsCloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScriptsMindScripts SoftwareTestingPune
 
Cloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScriptsCloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScriptsMindScripts SoftwareTestingPune
 

Similar to WPF with MVVM: From the Trenches (20)

Building an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernateBuilding an enterprise app in silverlight 4 and NHibernate
Building an enterprise app in silverlight 4 and NHibernate
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10
 
Portable Class Libraries and MVVM
Portable Class Libraries and MVVMPortable Class Libraries and MVVM
Portable Class Libraries and MVVM
 
J2EE pattern 5
J2EE pattern 5J2EE pattern 5
J2EE pattern 5
 
Presentation Model
Presentation ModelPresentation Model
Presentation Model
 
Machine Learning & Amazon SageMaker
Machine Learning & Amazon SageMakerMachine Learning & Amazon SageMaker
Machine Learning & Amazon SageMaker
 
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
Mvc vs mvp vs mvvm  a guide on architecture presentation patternsMvc vs mvp vs mvvm  a guide on architecture presentation patterns
Mvc vs mvp vs mvvm a guide on architecture presentation patterns
 
Mvvm pattern
Mvvm patternMvvm pattern
Mvvm pattern
 
MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
 
Deep Dive: MVC Controller Architecture
Deep Dive: MVC Controller ArchitectureDeep Dive: MVC Controller Architecture
Deep Dive: MVC Controller Architecture
 
MDA Vs Web Ratio for Non It
MDA Vs Web Ratio for Non ItMDA Vs Web Ratio for Non It
MDA Vs Web Ratio for Non It
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
PASSMN Summit 2009 Upgrade to SSAS 2008
PASSMN Summit 2009 Upgrade to SSAS 2008PASSMN Summit 2009 Upgrade to SSAS 2008
PASSMN Summit 2009 Upgrade to SSAS 2008
 
Mvvw patterns
Mvvw patternsMvvw patterns
Mvvw patterns
 
A Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVMA Smooth Transition to HTML5 Using MVVM
A Smooth Transition to HTML5 Using MVVM
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Cloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScriptsCloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScripts
 
Cloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScriptsCloud computing Training Institutes in Pune : MindScripts
Cloud computing Training Institutes in Pune : MindScripts
 
Salesforce Certification Courses in Pune - MindScripts
Salesforce Certification Courses in Pune - MindScripts Salesforce Certification Courses in Pune - MindScripts
Salesforce Certification Courses in Pune - MindScripts
 

Recently uploaded

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Recently uploaded (20)

How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

WPF with MVVM: From the Trenches

  • 1. WPF with MVVM: From the Trenches
  • 2. Brent Edwards Senior Consultant with Magenic BrentE@magenic.com @brentledwards brentedwards.net
  • 3. Why ‘From the Trenches’?
  • 4.
  • 7. Why is it cool?
  • 8. How is it used?
  • 9. Helpful tricks to make life easier
  • 10. Useful tools that make debugging suck less
  • 11.
  • 12. What is MVVM? Model Business logic Business Object View Presentation XAML View Model Functionality Model for the View
  • 13. Why is MVVM Cool? Separates Presentation from Functionality Promotes testability Works great with Data Binding Easy collaboration with Designers No code-behinds
  • 14. Cost of MVVM No built in IDE support All interactions must be manually wired up New and shiny, but fragmented Lots of different frameworks Lots of different opinions
  • 16. DataContext What is it? A way to give elements a scope for data binding Why is it cool? Makes it easy to bind controls Can be static or dynamic
  • 17. DataContext How is it used? Statically OR
  • 18. DataContext How is it used? Dynamically From code
  • 19. Data Binding What is it? A way for applications to present and interact with data Why is it cool? Simple syntax to set up, WPF does the rest
  • 20. Data Binding How is it used? Binding syntax in XAML Two Way (Default Behavior) Implement INotifyPropertyChanged on view model or business object
  • 21. Commanding What is it? A way to bind commands to a DataContext Why is it cool? Can wire UI events to fire commands on View Model Can pass parameters via binding
  • 22. Commanding How is it used? Expose ICommand property on View Model Assign a command to the property Prism’s DelegateCommand Bind to command in XAML
  • 24. Data Templates What is it? A way to define the presentation of your data Why is it cool? Can give a ‘look’ to your business objects You can leverage data binding
  • 25. Data Templates How is it used?
  • 27. Data Triggers What is it? Set style properties based on data values Why is it cool? Change presentation based on data properties
  • 28. Data Triggers How is it used?
  • 30. Value Converters What is it? Converts data value to format required by UI Why is it cool? Easy way to convert DateTime, Decimals, Integers or Booleans
  • 31. Value Converters How is it used? Implement IValueConverter Convert, ConvertBack Include in Resources with a Key Use it!
  • 33. Data Template Selectors What is it? Select DataTemplate based on custom logic Why is it cool Select DataTemplate based on properties on view models or business objects Can be unit tested
  • 34. Data Template Selectors How is it used? Inherit from DataTemplateSelector Add properties for the DataTemplates to select from Override SelectTemplate Add logic to actually select the template Add DataTemplates to XAML
  • 35. Data Template Selectors How is it used? Add DataTemplateSelector to XAML Use it! ContentControl ListView ListBox
  • 37. Helpful Tricks [To make life easier]
  • 38. Event Aggregator / Message Bus What is it? Centralized location to route [Events | Messages] Why is it cool? Great way to decouple view models Makes testing a breeze
  • 39. Event Aggregator / Message Bus How is it used? Use an IOC container Castle Windsor Implement as a Singleton Static property Important that all calls route through same instance Options Prism’s Event Aggregator Roll your own
  • 40. Event Aggregator / Message Bus [Demo]
  • 41. Navigation The Problem Views coupled with other Views View Models know about Views No separation of concerns No testability
  • 42. Navigation A Solution Some Convention, Some Configuration Leverage [Event Aggregator | Message Bus] Leverage IOC Castle Windsor Leverage Reflection
  • 43. Navigation Convention View Models all have default constructors View Models have an optional Load method with 0 or 1 argument(s)
  • 44. Navigation Configuration – Key Players ViewTargets ViewConfiguration ViewController ViewResult ViewFactory ContainerConfiguration
  • 45. Navigation Configuration - ViewTargets Enumerates the views which can be navigated to The glue that sticks everything together
  • 46. Navigation Configuration - ViewConfiguration Pairs a View with an optional View Model Associated to a ViewTarget in the IOC Container
  • 47. Navigation Configuration - ViewController The only object that interacts with the UI framework Listens for [Events | Messages] related to showing views Gives view details to ViewFactory to be built
  • 48. Navigation Configuration – ViewFactory Resolves ViewConfiguration for the requested View Dynamically creates the View and View Model Loads the View Model with optional params using reflection Gives back a ViewResult
  • 49. Navigation Configuration – ViewResult Result of the dynamic build process Has the built View along with any relevant data Used by ViewController to show the View
  • 51. Modal Dialogs Problem Modal dialogs stall tests [MessageBox| OpenFileDialog| PrintDialog] How can you leverage these and keep view models testable?
  • 52. Modal Dialogs Option 1 Wrap them up! Define interface IMessageShower Define implementation MessageShower Wire up with IOC Container Castle Windsor Test with mocks RhinoMocks
  • 53. Modal Dialogs Option 2 [Event Aggregator | Message Bus] Create [Events | Messages] Create class listen for [Events | Messages] that get published Test by verifying [Events | Messages] are published Good for “Fire and Forget” Breaks down if results are returned
  • 55. Magic with ContentControl The Problem Editable View and Read Only View Views have identical layout TextBox in for Editable Label for Read Only
  • 56. Magic with ContentControl A Solution – ContentControl! DataTriggers Give different presentation depending on data values Works dynamically DataTemplateSelector Select which DataTemplate to use Only works when initially bound
  • 58. Useful Tools [To make debugging suck less]
  • 59. Snoop Inspects visual tree Shows properties Shows events Can show 3D representation
  • 61. Output Window Shows binding expression errors Could be in immediate window instead
  • 63. Valuable Links Josh Smith http://joshsmithonwpf.wordpress.com/ Advanced MVVM – Book Snoop http://snoopwpf.codeplex.com/ Prism http://compositewpf.codeplex.com/Wikipage
  • 65. Brent Edwards Senior Consultant with Magenic BrentE@magenic.com @brentledwards brentedwards.net

Editor's Notes

  1. UI Architect for 2 WPF projects leveraging MVVM.
  2. This is not about WPF or MVVM. This is about WPF WITH MVVM.