Download presentation
Presentation is loading. Please wait.
Published byLouisa Walters Modified over 9 years ago
1
Building Silverlight Applications Using the MVVM pattern An Introduction by Peter Messenger Senior Developer – Qmastor http://www.petermessenger.com
2
Silverlight and WPF User interface programming platform operates on top of the NET framework WPF is windows based Silverlight can run in web browsers, Windows and Apple, Windows Mobile etc –Use XAML (eXtensible Application Markup Language) –Have powerful databinding capabilities –Have command properties where screen elements can perform actions
3
Example XAML and Code Behind Hello World Example Using XAML View and “traditional” events and elements knowledge Simple.xaml
4
What is the MVVM pattern? Model View ViewModel is a coding pattern to develop Silverlight and WPF applications. Main aims –Cleaner code and easier to maintain and extend –Testable applications –Thinner user interface layer –Easier for User Interface designers to concentrate on how the application will look and coders to concentrate on what the application will do
5
Concepts of MVVM Three broad categories of objects –Model Contain data consumed and modified by user Include things like business rule processing, input validation, change tracking and other things relating to system data In database terms, this could be considered as tables, views and stored procedures used to update them
6
Concepts of MVVM Three broad categories of objects –View UI control that displays data Allows the user to modify the state of the data via keyboard or mouse Shows video, images or whatever else needs to be displayed Bound to the model via databinding
7
Concepts of MVVM Three broad categories of objects –ViewModel Model of a view (abstraction) Expose properties to which views are bound Including properties that return command objects Notify view of changes via PropertyChangedEvent (INotifyPropertyChanged interface) Collections of data can be updated via ObservableCollections Gets update of data via two way binding in the view
8
Example XAML and Code Behind Hello World Example Using XAML View bound to ViewModel Binding.xaml
9
Comments As can be seen, this simple example takes some setting up and increased code When you work on more complicated programs and use inheritance, this becomes much less of an issue There are several different open source templates that can be used to get started
10
My Experience with MVVM Spent last 8 months developing Silverlight application for Qmastor –Web interface for NSW mines to interact with the new Newcastle Coal Port to manage their coal shipments –Trialled using the MVVM pattern with great success –Other developers in the company then started using it –Likely to be the company defacto standard from now on
11
Discussion and Code More complicated example Data Entry and Validation Employee database MainPage.xaml
12
Questions
13
Links Wikipedia http://en.wikipedia.org/wiki/Model_View_ViewModel Understanding the MVVM pattern http://live.visitmix.com/MIX10/Sessions/EX14 WPF Apps using the MVVM pattern http://msdn.microsoft.com/en-us/magazine/dd419663.aspx MVVM Light Toolkit http://www.galasoft.ch/mvvm/getstarted/ Advanced MVVM – Josh Smith http://www.advancedmvvm.com
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.