SlideShare uma empresa Scribd logo
1 de 30
SMTC WenemRmnrnr XNXNXNNXNX SNS, EndndjHsmnwmd ndvbsn@infusion.com August 29, 2007 Silverlight 3 Best Practice Do’s and Don’ts
Stephen Kennedy (skennedy@infusion.com) Presenter
Design Patterns Development Optimizations Overview
Design patterns Silverlight 3
Model View Controller/Presenter Pattern Problem: Decoupling data display logic from the business logic that maintains and updates it Solution: MVC Pattern separates the modeling of the domain, presentation, and actions based on user input into three separate classes: Model: Manages behavior/data of the application domain responds to requests for information about its state (usually from View) responds to instructions to change its state (usually from Controller). View: Manages the display information Controller: Informs the Model to change its state by interpreting inputs from keyboard, mouse and external instructions.
Developed by Martin Fowler, and is an extension of MVP Again, the View is separated from its behavior and state A Presentation Model is introduced, which acts as an abstraction of the view – so the view is merely a rendering of the Presentation Model View has a reference to Presentation Model, but Presentation Model has no reference to view Presentation Model
MVP/MVC  nice for web and thick client Good for ASP.NET,WinForms, WPF (as a start) Good for Silverlight as a start What you’re used to
Identical to Presentation Model, but engineered by John Gossman to utilize WPF Dependency Properties and Commands to bind UI to abstraction Ideal as it allows abstraction, called the ViewModel, to be tested Also allows for any UI to bind to ViewModel fields to show and modify the data XAML controls / Elements bind to properties in the ViewModel class Use Model-View-ViewModel Pattern
Model POCO – no Dependency Properties / Routed Events No UI knowledge - pure data Design Patterns: MVVM
View Model No knowledge of the view Exposes the model(s) / custom properties used in the view Use ObservableCollection<T> for collections of data Implement INotifyPropertyChanged for custom properties Should be able to act as a command line interface to the view No Dependency Properties Design Patterns: MVVM
View Binds to the ViewModel (DataContext) Use converters to bind visual elements to ViewModel / Model properties ie: Model’s Temperature  Colour Brush Events are hooked up through either code-behind or commanding Commanding better, but no OOB support in SL Silverlight Extensions project on CodePlex Custom Behaviors Composite Application Guidance/Library (Prism) Design Patterns: MVVM
View and ViewModel Binding ViewModel.cs App.xaml.cs ModelData md; public ViewModel() {   md=new ModelData(); } public string Data {    get{  return md.Data;}    set{ md.Data = value;} } public App()  { View view = new View(); view.DataContext= new ViewModel();  //… }  View.xaml ... <TextBox  Content=“{Binding Data}” ... /> ...
Can use “regular” property procedures in ViewModel If binding a collection to a DataGrid, etc., prefer the ObservableCollection<> (or non-generic equivalent) to sync updates back to the Model automatically MVVM Data Binding
MVVM Collection Item Binding The View should never bind to the data directly, but bind to a ViewModel If a collection of data is to be displayed in the View, the main ViewModel should expose an ObservableCollection of an additional ViewModel class that exposes properties, and thus, data Property ... Property ... Property ... Property ... Property ... Property ... public ObservableCollectionMyOC ...{ return new ObservableCollection<ViewModel2> ... }  Property ... Property ... Property ... <DataGridItemsSource=“ {Binding MyOC}” .../> Property ... Property ... Property ... Property ... Property ... Property ... ViewModel2 The View ViewModel1
Issue: changing property values in ViewModel does not always update bound control in View Solution: have ViewModel implement INotifyPropertyChanged interface, and raise PropertyChanged event in each property Or better yet, create a base ViewModel class and have each ViewModel subclass it Property Binding
Attached Properties in XAML can also be used in lieu of missing Command  Create Command, expose as property in ViewModel Create static class with Attached Property Add namespace to XAML screen Place Attached Property in desired control Commands and Attached Properties
Attached Property
ViewModel and XAML with Attached Property
The View knows about the ViewModel, but the ViewModel does not know about the View ViewModel is assigned to the DataContext of the View (Silverlight XAML) In xaml.cs codebehind for page In App.xaml.cs In XAML via Resource Other Associating ViewModel with View
Create ViewModel base class (implement INotifyPropertyChanged) Have all ViewModels subclass base Expose NO models to View directly Use Attached Properties as ‘workaround’ to lack of Commands in Silverlight controls Possibly Behaviors … Good practices …
Development Silverlight 3
Easy to get sloppy – name all controls/elements UI elements should have the same naming convention as your private class variables (that’s what they become) ie: <Button x:Name=“_submitButton” /> Prefix every resource with a “namespace” “Storyboards.FlashUserImage” “Brushes.ButtonBackground” “Templates.GiftsListBox” Development
Use new Data Annotations framework (.NET 3.5/4.0) ,[object Object]
[Range(1,100)]
[StringLength(15)]
[RegularExpresion(“^M.*”)]
[CustomValidation(typeof(MyValidator, “MyValidationMethod”))Can be applied at class or property level Data Annotations are your friend
Import System.ComponentModel.DataAnnotations Annotate properties/methods Can specify custom validation method TIP: Use a convention pattern ,[object Object]
Use a method name convention (use a constant)Data Annotations
Pull common control appearance into styles Break app-wide resources into multiple files (by merging resource dictionaries into App.xaml) ,[object Object]

Mais conteúdo relacionado

Mais procurados

Just a View: An Introduction To Model-View-Controller Pattern
Just a View:  An Introduction To Model-View-Controller PatternJust a View:  An Introduction To Model-View-Controller Pattern
Just a View: An Introduction To Model-View-Controller PatternAaron Nordyke
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC StructureDipika Wadhvani
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderSimon Massey
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJSAustin Condiff
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fairTech_MX
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)icapetillos
 
Ui design patterns
Ui design patternsUi design patterns
Ui design patternsJorge Ortiz
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMMudasir Qazi
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)M Ahsan Khan
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architectureravindraquicsolv
 
Model View Controller(MVC)
Model View Controller(MVC)Model View Controller(MVC)
Model View Controller(MVC)Himanshu Chawla
 

Mais procurados (20)

Just a View: An Introduction To Model-View-Controller Pattern
Just a View:  An Introduction To Model-View-Controller PatternJust a View:  An Introduction To Model-View-Controller Pattern
Just a View: An Introduction To Model-View-Controller Pattern
 
Ppt of Basic MVC Structure
Ppt of Basic MVC StructurePpt of Basic MVC Structure
Ppt of Basic MVC Structure
 
MVC
MVCMVC
MVC
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-BinderDesign Patterns in ZK: Java MVVM as Model-View-Binder
Design Patterns in ZK: Java MVVM as Model-View-Binder
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
Leveling up with AngularJS
Leveling up with AngularJSLeveling up with AngularJS
Leveling up with AngularJS
 
Mvc fundamental
Mvc fundamentalMvc fundamental
Mvc fundamental
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Mvc pattern and implementation in java fair
Mvc   pattern   and implementation   in   java fairMvc   pattern   and implementation   in   java fair
Mvc pattern and implementation in java fair
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
Ui design patterns
Ui design patternsUi design patterns
Ui design patterns
 
Design Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVMDesign Pattern - MVC, MVP and MVVM
Design Pattern - MVC, MVP and MVVM
 
MVVM In Use
MVVM In UseMVVM In Use
MVVM In Use
 
Model view controller (mvc)
Model view controller (mvc)Model view controller (mvc)
Model view controller (mvc)
 
Introduction to mvc architecture
Introduction to mvc architectureIntroduction to mvc architecture
Introduction to mvc architecture
 
Mvc, mvp, mvvm...
Mvc, mvp, mvvm...Mvc, mvp, mvvm...
Mvc, mvp, mvvm...
 
Why Use MVC?
Why Use MVC?Why Use MVC?
Why Use MVC?
 
MVC architecture
MVC architectureMVC architecture
MVC architecture
 
Model View Controller(MVC)
Model View Controller(MVC)Model View Controller(MVC)
Model View Controller(MVC)
 

Semelhante a Stephen Kennedy Silverlight 3 Deep Dive

MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCAnton Krasnoshchok
 
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
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentationBhavin Shah
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecturebitburner93
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamentalldcphuc
 
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
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
SUE AGILE MVVM (English)
SUE AGILE MVVM (English)SUE AGILE MVVM (English)
SUE AGILE MVVM (English)Sabino Labarile
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10Bryan Anderson
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & AngularAlexe Bogdan
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Svetlin Nakov
 

Semelhante a Stephen Kennedy Silverlight 3 Deep Dive (20)

MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
 
Test
TestTest
Test
 
MVC in PHP
MVC in PHPMVC in PHP
MVC in PHP
 
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
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
Code Camp 06 Model View Presenter Architecture
Code Camp 06   Model View Presenter ArchitectureCode Camp 06   Model View Presenter Architecture
Code Camp 06 Model View Presenter Architecture
 
ASP.NET MVC Fundamental
ASP.NET MVC FundamentalASP.NET MVC Fundamental
ASP.NET MVC Fundamental
 
Jinal desai .net
Jinal desai .netJinal desai .net
Jinal desai .net
 
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
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
MVC
MVCMVC
MVC
 
MVC & backbone.js
MVC & backbone.jsMVC & backbone.js
MVC & backbone.js
 
SUE AGILE MVVM (English)
SUE AGILE MVVM (English)SUE AGILE MVVM (English)
SUE AGILE MVVM (English)
 
Mvvm in the real world tccc10
Mvvm in the real world   tccc10Mvvm in the real world   tccc10
Mvvm in the real world tccc10
 
MVC 4
MVC 4MVC 4
MVC 4
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
MVC Training Part 1
MVC Training Part 1MVC Training Part 1
MVC Training Part 1
 
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
Architectural Patterns and Software Architectures: Client-Server, Multi-Tier,...
 

Último

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
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
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
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
 
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
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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
 
🐬 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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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
 
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
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
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
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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
 
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...
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
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
 
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...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 

Stephen Kennedy Silverlight 3 Deep Dive

  • 1. SMTC WenemRmnrnr XNXNXNNXNX SNS, EndndjHsmnwmd ndvbsn@infusion.com August 29, 2007 Silverlight 3 Best Practice Do’s and Don’ts
  • 3. Design Patterns Development Optimizations Overview
  • 5. Model View Controller/Presenter Pattern Problem: Decoupling data display logic from the business logic that maintains and updates it Solution: MVC Pattern separates the modeling of the domain, presentation, and actions based on user input into three separate classes: Model: Manages behavior/data of the application domain responds to requests for information about its state (usually from View) responds to instructions to change its state (usually from Controller). View: Manages the display information Controller: Informs the Model to change its state by interpreting inputs from keyboard, mouse and external instructions.
  • 6. Developed by Martin Fowler, and is an extension of MVP Again, the View is separated from its behavior and state A Presentation Model is introduced, which acts as an abstraction of the view – so the view is merely a rendering of the Presentation Model View has a reference to Presentation Model, but Presentation Model has no reference to view Presentation Model
  • 7. MVP/MVC nice for web and thick client Good for ASP.NET,WinForms, WPF (as a start) Good for Silverlight as a start What you’re used to
  • 8. Identical to Presentation Model, but engineered by John Gossman to utilize WPF Dependency Properties and Commands to bind UI to abstraction Ideal as it allows abstraction, called the ViewModel, to be tested Also allows for any UI to bind to ViewModel fields to show and modify the data XAML controls / Elements bind to properties in the ViewModel class Use Model-View-ViewModel Pattern
  • 9. Model POCO – no Dependency Properties / Routed Events No UI knowledge - pure data Design Patterns: MVVM
  • 10. View Model No knowledge of the view Exposes the model(s) / custom properties used in the view Use ObservableCollection<T> for collections of data Implement INotifyPropertyChanged for custom properties Should be able to act as a command line interface to the view No Dependency Properties Design Patterns: MVVM
  • 11. View Binds to the ViewModel (DataContext) Use converters to bind visual elements to ViewModel / Model properties ie: Model’s Temperature  Colour Brush Events are hooked up through either code-behind or commanding Commanding better, but no OOB support in SL Silverlight Extensions project on CodePlex Custom Behaviors Composite Application Guidance/Library (Prism) Design Patterns: MVVM
  • 12. View and ViewModel Binding ViewModel.cs App.xaml.cs ModelData md; public ViewModel() { md=new ModelData(); } public string Data { get{ return md.Data;} set{ md.Data = value;} } public App() { View view = new View(); view.DataContext= new ViewModel(); //… } View.xaml ... <TextBox Content=“{Binding Data}” ... /> ...
  • 13. Can use “regular” property procedures in ViewModel If binding a collection to a DataGrid, etc., prefer the ObservableCollection<> (or non-generic equivalent) to sync updates back to the Model automatically MVVM Data Binding
  • 14. MVVM Collection Item Binding The View should never bind to the data directly, but bind to a ViewModel If a collection of data is to be displayed in the View, the main ViewModel should expose an ObservableCollection of an additional ViewModel class that exposes properties, and thus, data Property ... Property ... Property ... Property ... Property ... Property ... public ObservableCollectionMyOC ...{ return new ObservableCollection<ViewModel2> ... } Property ... Property ... Property ... <DataGridItemsSource=“ {Binding MyOC}” .../> Property ... Property ... Property ... Property ... Property ... Property ... ViewModel2 The View ViewModel1
  • 15. Issue: changing property values in ViewModel does not always update bound control in View Solution: have ViewModel implement INotifyPropertyChanged interface, and raise PropertyChanged event in each property Or better yet, create a base ViewModel class and have each ViewModel subclass it Property Binding
  • 16. Attached Properties in XAML can also be used in lieu of missing Command Create Command, expose as property in ViewModel Create static class with Attached Property Add namespace to XAML screen Place Attached Property in desired control Commands and Attached Properties
  • 18. ViewModel and XAML with Attached Property
  • 19. The View knows about the ViewModel, but the ViewModel does not know about the View ViewModel is assigned to the DataContext of the View (Silverlight XAML) In xaml.cs codebehind for page In App.xaml.cs In XAML via Resource Other Associating ViewModel with View
  • 20. Create ViewModel base class (implement INotifyPropertyChanged) Have all ViewModels subclass base Expose NO models to View directly Use Attached Properties as ‘workaround’ to lack of Commands in Silverlight controls Possibly Behaviors … Good practices …
  • 22. Easy to get sloppy – name all controls/elements UI elements should have the same naming convention as your private class variables (that’s what they become) ie: <Button x:Name=“_submitButton” /> Prefix every resource with a “namespace” “Storyboards.FlashUserImage” “Brushes.ButtonBackground” “Templates.GiftsListBox” Development
  • 23.
  • 27. [CustomValidation(typeof(MyValidator, “MyValidationMethod”))Can be applied at class or property level Data Annotations are your friend
  • 28.
  • 29. Use a method name convention (use a constant)Data Annotations
  • 30.
  • 38. Use Visibility rather than Opacity to hide objects Use transparent control backgrounds sparingly Avoid long-running JavaScript tasks and more Performance Tips …
  • 39. Never make the user wait and wonder Progress, progress, progress Minimize XAP size (this initial download) Make services prime, but remember Progress, progress, progress User interaction
  • 40. Resizing Blending Drawing resultant pixels onscreen ALL can be done with GPU acceleration enabled In <object> tag <parm name=“enableGPUAcceleration” value=“true” /> Hardware optimization

Notas do Editor

  1. Introduced in .NET 3.5 SP1, further support in .NET 4.0 Allows you to annotate your classes with what it means for an instance to be valid Place it on properties When value is set, annotations get evaluated and an exception is thrown if they fail Silverlight 3 controls automatically react to exceptions and display an error state (a visual state)
  2. Note the order is important