SlideShare uma empresa Scribd logo
1 de 25
Understanding the
MVVM pattern
Laurent Bugnion
Senior User Experience Integrator
IdentityMine
http://[blog|www].galasoft.ch
What is MVVM?

 • A weird acronym
   • Model – View – ViewModel
   • « MVVM in a SLOOB with SLUT »


 • Woven into WPF/SL
 • Some confusion:
   • MVVM is really just the pattern
   • The rest are helpers, practices, etc
The MVC pattern




                  Model                View




                          Controller
The Passive View pattern




                 Model                  View




                           Controller
The Presentation Model pattern




                 Model                  View

                                        DataBinding


                         Presentation
                            Model
                         (ViewModel)
Blendability

  • Testability, Maintainability, Blendability

  • “The ability to be edited in Blend”

     • (and Visual Studio designer…)

  • Differentiate code in design and runtime

  • Create design time data
Hello MVVM (and Hi Blend)
Bridging the gap


                            View


                   DataBinding      Commands   Messages




                             ViewModel




                            Model
Bridging the gap

                                                View


            View
                            Messages       ViewModel


         ViewModel
                                         View

                   Messages
                   + callback

                                       ViewModel
Commands

 • “Point of entry” for a method”

 • Can be data bound

 • ICommand interface

   • Execute method

   • CanExecute method

   • CanExecuteChanged event handler
Commands
and RelayCommands
RelayCommands


  RelayCommand MyCommand
    = new RelayCommand(
      () => ...,
      () => true | false);

  RelayCommand<T> MyGenericCommand
    = new RelayCommand<T>(
      p => ...,
      p => true | false);
Messaging

 • Should be simple by default

 • Possible to open filtered channels

    • To a target Type (or an Interface)

    • With a Token

    • With various Messenger instances

 • No constraints at all
Messaging
Messaging


  Messenger.Default.Register<T>(
      this,
      p => DoSomething(p));

  Messenger.Default.Send<T>(p);
MVVM Light Toolkit

  • “Breaking the monotony”

  • http://www.galasoft.ch/mvvm/getstarted

  • http://mvvmlight.codeplex.com

  • V3 released at MIX10

  • Keep it small
  • Keep it simple
MVVM Light Libraries V3

  • ESSENTIALS
    • RelayCommand
    • Messenger
    • ViewModelBase
  • EXTRAS
    • EventToCommand
    • DispatcherHelper
MVVM Light Tools V3


 • Project templates (VS + Blend)


 • Item templates (VS + Blend)


 • Code snippets
MVVM Light Toolkit,
Unity,
Blendability
Flaws of MVVM

  • Too much code needed
    • INotifyPropertyChanged
    • Commands
  • Some operations are tricky (set focus…)
  • Not applicable to ASP.NET, etc
  • Message to community is not clear
Debunking the myths

  • “No code in the code behind”
    • “If you put code in the View's code-behind, the
     MVVM police will take your family away”
    • “No need for converters”

  • “MVVM is only suitable for big projects”
  • “MVVM costs performance”
  • “MVVM is complex / makes my head hurt”
Debunking the myths

  • “I don’t need separation because I don’t
   have a designer”
  • “You cannot use MVVM with other
   patterns”
  • “MVVM will make you rich and attractive”
MVVM on the
Windows Phone 7
http://blog.galasoft.ch
http://www.galasoft.ch/mvvm/getstarted
@LBugnion

Mais conteúdo relacionado

Mais procurados

MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPFS V
 
Learn skills technologies
Learn skills technologiesLearn skills technologies
Learn skills technologiess_shankar1977
 
Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5Chris Bannon
 
[Mas 500] Web Basics
[Mas 500] Web Basics[Mas 500] Web Basics
[Mas 500] Web Basicsrahulbot
 
JavaScript Framework Smackdown
JavaScript Framework SmackdownJavaScript Framework Smackdown
JavaScript Framework Smackdownmeghantaylor
 
MVVM Light Toolkit Works Great, Less Complicated
MVVM Light ToolkitWorks Great, Less ComplicatedMVVM Light ToolkitWorks Great, Less Complicated
MVVM Light Toolkit Works Great, Less Complicatedmdc11
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2...WebStackAcademy
 
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
 
Gemeinsame View-Models mit XAML Technologien
Gemeinsame View-Models mit XAML TechnologienGemeinsame View-Models mit XAML Technologien
Gemeinsame View-Models mit XAML TechnologienChristian Nagel
 
MVVM Windows UWP apps with Template 10
MVVM Windows UWP apps with Template 10MVVM Windows UWP apps with Template 10
MVVM Windows UWP apps with Template 10Jiri Danihelka
 
Javascript(2)
Javascript(2)Javascript(2)
Javascript(2)tomcoh
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!Muhammad Ghazali
 

Mais procurados (18)

MVVM with WPF
MVVM with WPFMVVM with WPF
MVVM with WPF
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
XAML/C# to HTML5/JS
XAML/C#  to HTML5/JS XAML/C#  to HTML5/JS
XAML/C# to HTML5/JS
 
Learn skills technologies
Learn skills technologiesLearn skills technologies
Learn skills technologies
 
Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5Migrating MVVM Applications to HTML5
Migrating MVVM Applications to HTML5
 
Introduction to Umbraco
Introduction to UmbracoIntroduction to Umbraco
Introduction to Umbraco
 
[Mas 500] Web Basics
[Mas 500] Web Basics[Mas 500] Web Basics
[Mas 500] Web Basics
 
JavaScript Framework Smackdown
JavaScript Framework SmackdownJavaScript Framework Smackdown
JavaScript Framework Smackdown
 
MVVM Light Toolkit Works Great, Less Complicated
MVVM Light ToolkitWorks Great, Less ComplicatedMVVM Light ToolkitWorks Great, Less Complicated
MVVM Light Toolkit Works Great, Less Complicated
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 2...
 
MVVM frameworks
MVVM frameworksMVVM frameworks
MVVM frameworks
 
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
 
MVVM with Kendo UI
MVVM with Kendo UIMVVM with Kendo UI
MVVM with Kendo UI
 
Gemeinsame View-Models mit XAML Technologien
Gemeinsame View-Models mit XAML TechnologienGemeinsame View-Models mit XAML Technologien
Gemeinsame View-Models mit XAML Technologien
 
MVVM Windows UWP apps with Template 10
MVVM Windows UWP apps with Template 10MVVM Windows UWP apps with Template 10
MVVM Windows UWP apps with Template 10
 
Beginning In J2EE
Beginning In J2EEBeginning In J2EE
Beginning In J2EE
 
Javascript(2)
Javascript(2)Javascript(2)
Javascript(2)
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
 

Semelhante a Understanding The MVVM Pattern (TechDays Belgium)

Advanced MVVM in Windows 8
Advanced MVVM in Windows 8Advanced MVVM in Windows 8
Advanced MVVM in Windows 8Gill Cleeren
 
MVP Mix 2015 Leveraging MVVM on all Platforms
MVP Mix 2015  Leveraging MVVM on all PlatformsMVP Mix 2015  Leveraging MVVM on all Platforms
MVP Mix 2015 Leveraging MVVM on all PlatformsJames Montemagno
 
An introduction to knockout.js
An introduction to knockout.jsAn introduction to knockout.js
An introduction to knockout.jsEmanuele DelBono
 
JavaScript TDD
JavaScript TDDJavaScript TDD
JavaScript TDDUri Lavi
 
MVVM for Modern Applications
MVVM for Modern ApplicationsMVVM for Modern Applications
MVVM for Modern ApplicationsJeremy Likness
 
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
 
Windows Phone App with MVVM design patten
Windows Phone App with MVVM design pattenWindows Phone App with MVVM design patten
Windows Phone App with MVVM design pattenKamalakannan Annamalai
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVMJiri Danihelka
 
WPF For Beginners - Learn in 3 days
WPF For Beginners  - Learn in 3 daysWPF For Beginners  - Learn in 3 days
WPF For Beginners - Learn in 3 daysUdaya Kumar
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET WebskillsCaleb Jenkins
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture Jiby John
 
MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentationG ABHISEK
 
Model View Madness
Model View MadnessModel View Madness
Model View MadnessMike Wilcox
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesQamar Abbas
 
Building databound JavaScript apps with Knockoutjs
Building databound JavaScript apps with KnockoutjsBuilding databound JavaScript apps with Knockoutjs
Building databound JavaScript apps with KnockoutjsNish Anil
 
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCrossC# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCrossFlavius-Radu Demian
 
Sugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a timeSugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a timeEinar Ingebrigtsen
 

Semelhante a Understanding The MVVM Pattern (TechDays Belgium) (20)

Advanced MVVM in Windows 8
Advanced MVVM in Windows 8Advanced MVVM in Windows 8
Advanced MVVM in Windows 8
 
MVP Mix 2015 Leveraging MVVM on all Platforms
MVP Mix 2015  Leveraging MVVM on all PlatformsMVP Mix 2015  Leveraging MVVM on all Platforms
MVP Mix 2015 Leveraging MVVM on all Platforms
 
MVVM and Prism
MVVM and PrismMVVM and Prism
MVVM and Prism
 
Adopting MVVM
Adopting MVVMAdopting MVVM
Adopting MVVM
 
An introduction to knockout.js
An introduction to knockout.jsAn introduction to knockout.js
An introduction to knockout.js
 
JavaScript TDD
JavaScript TDDJavaScript TDD
JavaScript TDD
 
MVVM for Modern Applications
MVVM for Modern ApplicationsMVVM for Modern Applications
MVVM for Modern Applications
 
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
 
Windows Phone App with MVVM design patten
Windows Phone App with MVVM design pattenWindows Phone App with MVVM design patten
Windows Phone App with MVVM design patten
 
Prism library and MVVM
Prism library and MVVMPrism library and MVVM
Prism library and MVVM
 
WPF For Beginners - Learn in 3 days
WPF For Beginners  - Learn in 3 daysWPF For Beginners  - Learn in 3 days
WPF For Beginners - Learn in 3 days
 
Modern ASP.NET Webskills
Modern ASP.NET WebskillsModern ASP.NET Webskills
Modern ASP.NET Webskills
 
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Applied MVVM in Windows 8 apps: not your typical MVVM session!Applied MVVM in Windows 8 apps: not your typical MVVM session!
Applied MVVM in Windows 8 apps: not your typical MVVM session!
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
 
MVVM in iOS presentation
MVVM in iOS presentationMVVM in iOS presentation
MVVM in iOS presentation
 
Model View Madness
Model View MadnessModel View Madness
Model View Madness
 
Mobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelinesMobile App Architectures & Coding guidelines
Mobile App Architectures & Coding guidelines
 
Building databound JavaScript apps with Knockoutjs
Building databound JavaScript apps with KnockoutjsBuilding databound JavaScript apps with Knockoutjs
Building databound JavaScript apps with Knockoutjs
 
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCrossC# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
 
Sugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a timeSugarcoating your frontend one ViewModel at a time
Sugarcoating your frontend one ViewModel at a time
 

Último

[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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
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
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
🐬 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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Último (20)

[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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
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
 
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
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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...
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

Understanding The MVVM Pattern (TechDays Belgium)

  • 1.
  • 2. Understanding the MVVM pattern Laurent Bugnion Senior User Experience Integrator IdentityMine http://[blog|www].galasoft.ch
  • 3. What is MVVM? • A weird acronym • Model – View – ViewModel • « MVVM in a SLOOB with SLUT » • Woven into WPF/SL • Some confusion: • MVVM is really just the pattern • The rest are helpers, practices, etc
  • 4. The MVC pattern Model View Controller
  • 5. The Passive View pattern Model View Controller
  • 6. The Presentation Model pattern Model View DataBinding Presentation Model (ViewModel)
  • 7. Blendability • Testability, Maintainability, Blendability • “The ability to be edited in Blend” • (and Visual Studio designer…) • Differentiate code in design and runtime • Create design time data
  • 8. Hello MVVM (and Hi Blend)
  • 9. Bridging the gap View DataBinding Commands Messages ViewModel Model
  • 10. Bridging the gap View View Messages ViewModel ViewModel View Messages + callback ViewModel
  • 11. Commands • “Point of entry” for a method” • Can be data bound • ICommand interface • Execute method • CanExecute method • CanExecuteChanged event handler
  • 13. RelayCommands RelayCommand MyCommand = new RelayCommand( () => ..., () => true | false); RelayCommand<T> MyGenericCommand = new RelayCommand<T>( p => ..., p => true | false);
  • 14. Messaging • Should be simple by default • Possible to open filtered channels • To a target Type (or an Interface) • With a Token • With various Messenger instances • No constraints at all
  • 16. Messaging Messenger.Default.Register<T>( this, p => DoSomething(p)); Messenger.Default.Send<T>(p);
  • 17. MVVM Light Toolkit • “Breaking the monotony” • http://www.galasoft.ch/mvvm/getstarted • http://mvvmlight.codeplex.com • V3 released at MIX10 • Keep it small • Keep it simple
  • 18. MVVM Light Libraries V3 • ESSENTIALS • RelayCommand • Messenger • ViewModelBase • EXTRAS • EventToCommand • DispatcherHelper
  • 19. MVVM Light Tools V3 • Project templates (VS + Blend) • Item templates (VS + Blend) • Code snippets
  • 21. Flaws of MVVM • Too much code needed • INotifyPropertyChanged • Commands • Some operations are tricky (set focus…) • Not applicable to ASP.NET, etc • Message to community is not clear
  • 22. Debunking the myths • “No code in the code behind” • “If you put code in the View's code-behind, the MVVM police will take your family away” • “No need for converters” • “MVVM is only suitable for big projects” • “MVVM costs performance” • “MVVM is complex / makes my head hurt”
  • 23. Debunking the myths • “I don’t need separation because I don’t have a designer” • “You cannot use MVVM with other patterns” • “MVVM will make you rich and attractive”

Notas do Editor

  1. Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  2. Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  3. Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  4. Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode
  5. Demo of connection to WCF service, fails in BlendShow how to attach to processIdentify problemIsInDesignMode