Pro WPF and Silverlight MVVM: Effective Application Development with Model-View-ViewModel

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

WPF and Silverlight are unlike any other user interface (UI) technologies. They have been built to a new paradigm that—if harnessed correctly—can yield unprecedented power and performance. This book shows you how to control that power to produce clean, testable, maintainable code. It is now recognized that any non-trivial WPF or Silverlight application needs be designed around the Model-View-ViewModel (MVVM) design pattern in order to unlock the technology's full data-binding potential.  However, the knowledge of how to do this is missing from a large part of the development community—even amongst those who work with WPF and Silverlight on a daily basis. Too often there is a reliance on programmatic interaction between controls and not enough trust in the technologies' data-binding capabilities. This leads to a clouding of design values and an inevitable loss of performance, scalability, and maintainability throughout the application. Pro WPF and Silverlight MVVM will show you how to arrange your application so that it can grow as much as required in any direction without danger of collapse. What you’ll learn Understand why the separation of an application’s View and its Model is paramount, including the history of Model-View-Presenter and Model-View-Controller. Apply WPF and Silverlight’s powerful data-binding model correctly. Examine how to organize an application targeting WPF or Silverlight, including unit-testing, source-control, separation of concerns, data serialization, and how to tie everything together with MVVM. Develop a full game development application using MVVM by example. How to serialize the Model without being invasive, how to implement a plug-in architecture that extends both the View and the Model, and how to handle Exceptions gracefully. Who this book is for Developers that wish to learn how to architect WPF or Silverlight applications to ensure maintainability, testability, and separation of concerns. Table of Contents Overview of WPF and Silverlight DataBinding Model-View Separation The ViewModel Events and Commands Validation Unit Testing Data Access Layer Application Support Sample Application

Author(s): Gary Hall
Edition: 1
Publisher: Apress
Year: 2010

Language: English
Pages: 272

Prelim......Page 1
Contents at a Glance......Page 6
Contents......Page 7
About the Author......Page 12
About the Technical Reviewer......Page 13
Acknowledgments......Page 14
Introduction......Page 15
Architecture......Page 17
DirectX, Not GDI+......Page 18
Media......Page 19
Styling and Templating......Page 20
What Is Silverlight?......Page 21
Silverlight 4......Page 22
Silverlight Targets More Browsers......Page 23
WPF or Silverlight?......Page 24
Partial Classes......Page 25
Extension Methods......Page 26
Compiler Directives......Page 27
Almost Codeless......Page 29
XAML Attributes......Page 30
XAML Content......Page 31
Type Converters......Page 32
Namespaces......Page 33
User Experience vs. User Interface......Page 34
Summary......Page 35
Dependency Objects......Page 37
Dependency Property Metadata......Page 38
Dependency Properties......Page 39
XAML Integration......Page 40
Property Value Inheritance......Page 41
Dynamic Objects......Page 42
XML Objects......Page 43
Two-Way (Read/Write) Binding......Page 44
One-Time Binding......Page 45
The DataContext......Page 46
Converter and ConverterParameter......Page 47
NotifyOnSourceUpdated and NotifyOnTargetUpdated......Page 48
Source and RelativeSource......Page 49
UpdateSourceExceptionFilter......Page 50
IValueConverter Interface......Page 51
IMultiValueConverter Interface......Page 55
ObjectDataProvider......Page 58
Object Construction......Page 59
Method Binding......Page 60
Debugging DataBindings......Page 62
TraceSources......Page 63
PresentationTraceSources......Page 64
The Logical and Visual Trees......Page 65
ControlTemplate......Page 66
DataTemplate......Page 68
Summary......Page 69
Dependencies......Page 71
Partitioning Dependencies with Assemblies......Page 73
MVVM Alternatives......Page 75
XAML Code Behind......Page 76
Model View......Page 78
Encapsulation......Page 82
Don’t Repeat Yourself (DRY)......Page 83
You Ain’t Gonna Need It (YAGNI)......Page 85
The Law of Demeter......Page 86
Unit Tests Are Proof that Code Works......Page 87
Why Many Do Not Test First......Page 88
Events......Page 89
Data Binding......Page 90
The Mediator Pattern......Page 91
Coupling and Cohesion......Page 92
Model-View-Presenter......Page 93
You Gotta Keep ’Em Separated......Page 94
Summary......Page 95
The MVVM Template Project......Page 97
The View......Page 102
The ViewModel......Page 104
Observer Pattern......Page 106
INotifyPropertyChanged Interface......Page 107
Observable Collections......Page 108
ObservableCollection......Page 109
CollectionViewSource......Page 110
Sorting......Page 111
Constructing ViewModels......Page 112
The Application......Page 113
The Main Window......Page 114
Dialogs......Page 115
Threading......Page 116
Alleviating Bound Tasks......Page 117
Increased Complexity......Page 119
Threading Problems In WPF and Silverlight......Page 120
Dispatcher and DispatcherObjects......Page 121
Pass Dispatcher to the ViewModel......Page 123
Using a Mediator......Page 124
Aspect Oriented Programming......Page 125
Summary......Page 126
Events in .NET......Page 127
Events in WPF and Silverlight......Page 128
Routing Strategies......Page 129
Limitations......Page 130
Commands......Page 131
ICommand Interface......Page 132
Routed Command Implementations......Page 133
Requirements......Page 135
Technical Design......Page 136
Implementation......Page 138
Usage......Page 139
Avoiding Events Using Dependency Injection......Page 142
Summary......Page 144
Validation......Page 145
The Validation Process......Page 146
Validate Method......Page 147
Constructors......Page 148
Filtering Validation Exceptions......Page 149
IDataErrorInfo Interface......Page 151
Model Implementation......Page 152
ViewModel Implementation......Page 153
Validation in Silverlight......Page 155
Validation.HasError Attached Property......Page 159
Summary......Page 160
Traditional Testing......Page 161
The Waterfall Methodology......Page 162
The Testing Afterthought......Page 163
Gaining Agility......Page 164
Automation......Page 165
Code Coverage......Page 166
Enforce Better Design......Page 167
Unit Testing with Visual Studio 2010......Page 168
Test Projects......Page 169
NUnit......Page 171
RhinoMocks......Page 172
Assertions......Page 174
Handling Exceptions......Page 175
AAA: Arrange, Act, Assert......Page 176
Summary......Page 178
Object-Relational Dichotomy......Page 179
Mapping Object Relationships......Page 184
Mapping Class Hierarchies......Page 185
Manual Implementation......Page 188
LINQ to SQL......Page 192
Entity Framework......Page 194
NHibernate......Page 195
Collaboration......Page 196
Unit of Work......Page 197
Generate, Not Create......Page 198
Summary......Page 199
Application Support......Page 201
Invasive Serialization......Page 202
External Serialization......Page 206
Natural Team Boundaries......Page 208
Import......Page 209
Export......Page 211
Container......Page 212
Extending A WPF Application......Page 213
Defining An Extension Contract......Page 214
Sharing User Interface Components......Page 216
Attaching a DataTemplate......Page 217
Single Process, Single AppDomain......Page 218
Summary......Page 219
The Application......Page 221
Money......Page 222
Account......Page 227
Testing Behavior......Page 236
Hiding All Model Contents......Page 238
View......Page 244
Summary......Page 257
¦ B......Page 259
¦ C......Page 260
¦ D......Page 262
¦ E......Page 263
¦ F......Page 264
¦ L......Page 265
¦ M......Page 266
¦ N......Page 267
¦ P, Q......Page 268
¦......Page 269
¦ T......Page 270
¦......Page 271
¦ W......Page 272
¦......Page 273