SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Kürzlich hochgeladen (20)

Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

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

Hinweis der Redaktion

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