PDF Developer's Guide to Microsoft Prism Library 5.0 for WPF

[Pages:382]Developer's Guide to Microsoft Prism Library 5.0 for WPF

Microsoft patterns & practices

April 2014

2

Copyright

This document is provided "as-is". Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. You may modify this document for your internal, reference purposes. ? 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Server, Windows Vista, Silverlight, Expression Blend, MSDN, IntelliSense, Visual C#, Visual C++, and Visual Studio are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.

3

Contents

Download and Setup Prism........................................................................................................................... 8 Documentation ......................................................................................................................................... 8 NuGet Packages ........................................................................................................................................ 8 Download and Setup the Prism Source Code ........................................................................................... 9 Adding Prism Library Source Projects to Solutions ................................................................................. 13 Related Downloads ................................................................................................................................. 13

What's New in Prism Library 5.0 for WPF ................................................................................................... 14 New Guidance......................................................................................................................................... 14 Changes in the Prism Library................................................................................................................... 14 CodePlex Issues Resolved ....................................................................................................................... 16 Example Code Changes ........................................................................................................................... 17 NuGet Packages Now Available .............................................................................................................. 18

The Team Who Brought You This Guide ..................................................................................................... 19 1: Introduction ............................................................................................................................................ 20

Why Use Prism? ...................................................................................................................................... 20 Prerequisites ........................................................................................................................................... 23 An Overview of Prism.............................................................................................................................. 24 2: Initializing Applications ........................................................................................................................... 37 What Is a Bootstrapper? ......................................................................................................................... 37 Key Decisions .......................................................................................................................................... 38 Core Scenarios ........................................................................................................................................ 38 3: Managing Dependencies Between Components.................................................................................... 45 Key Decision: Choosing a Dependency Injection Container ................................................................... 46 Core Scenarios ........................................................................................................................................ 47 Using Dependency Injection Containers and Services in Prism .............................................................. 51 IServiceLocator........................................................................................................................................ 52 Considerations for Using IServiceLocator ............................................................................................... 54 4: Modular Application Development ........................................................................................................ 55 Benefits of Building Modular Applications ............................................................................................. 55

4

Core Concepts ......................................................................................................................................... 56 Key Decisions .......................................................................................................................................... 60 Core Scenarios ........................................................................................................................................ 65 5: Implementing the MVVM Pattern .......................................................................................................... 77 Class Responsibilities and Characteristics............................................................................................... 77 Class Interactions .................................................................................................................................... 82 Construction and Wire-Up ...................................................................................................................... 93 Key Decisions .......................................................................................................................................... 96 6: Advanced MVVM Scenarios .................................................................................................................... 98 Commands .............................................................................................................................................. 98 Interaction Triggers and Commands..................................................................................................... 104 Handling Asynchronous Interactions .................................................................................................... 106 User Interaction Patterns...................................................................................................................... 108 Advanced Construction and Wire-Up ................................................................................................... 114 Testing MVVM Applications.................................................................................................................. 117 7: Composing the User Interface .............................................................................................................. 123 UI Layout Concepts ............................................................................................................................... 124 UI Layout Scenarios............................................................................................................................... 133 UI Design Guidance ............................................................................................................................... 150 UI Layout Key Decisions ........................................................................................................................ 165 8: Navigation ............................................................................................................................................. 167 Navigation in Prism ............................................................................................................................... 167 9: Communicating Between Loosely Coupled Components..................................................................... 190 Solution Commanding........................................................................................................................... 190 Region Context...................................................................................................................................... 193 Shared Services ..................................................................................................................................... 194 Event Aggregation................................................................................................................................. 195 10: Deploying Applications ....................................................................................................................... 202 Deploying WPF Prism Applications ....................................................................................................... 202 11: Glossary............................................................................................................................................... 207 12: Patterns in the Prism Library .............................................................................................................. 210

5

Adapter ................................................................................................................................................. 210 Application Controller Pattern.............................................................................................................. 211 Command Pattern................................................................................................................................. 211 Composite and Composite View ........................................................................................................... 211 Dependency Injection Pattern .............................................................................................................. 212 Event Aggregator Pattern ..................................................................................................................... 212 Fa?ade Pattern ...................................................................................................................................... 212 Inversion of Control Pattern ................................................................................................................. 213 Observer Pattern................................................................................................................................... 213 Model-View-ViewModel Pattern .......................................................................................................... 213 Registry Pattern .................................................................................................................................... 214 Repository Pattern ................................................................................................................................ 214 Separated Interface and Plug-In ........................................................................................................... 214 Service Locator Pattern......................................................................................................................... 214 13: Prism Library ....................................................................................................................................... 217 Add Reference using NuGet and Accessing the Library Source Code................................................... 218 Organization of the Prism Library ......................................................................................................... 218 The Prism Library Source ...................................................................................................................... 219 Modifying the Library............................................................................................................................ 219 Running the Tests.................................................................................................................................. 220 14: Upgrading from Prism Library 4.1 ....................................................................................................... 221 15: Extending the Prism Library ................................................................................................................ 224 Guidelines for Extensibility ................................................................................................................... 224 Recommendations for Modifying the Prism Library............................................................................. 225 Extensibility Points in the Prism Library................................................................................................ 226 Container and Bootstrapper ................................................................................................................. 227 Logging .................................................................................................................................................. 231 Modules ................................................................................................................................................ 232 Regions.................................................................................................................................................. 235 Region Navigation ................................................................................................................................. 240 View Model Locator .............................................................................................................................. 242

6

16: Code Samples...................................................................................................................................... 244 Installing Prism...................................................................................................................................... 244

Stock Trader Reference Implementation.................................................................................................. 248 Building and Running the Reference Implementation ......................................................................... 249 The Scenario.......................................................................................................................................... 251 Stock Trader RI Features ....................................................................................................................... 255 Logical Architecture .............................................................................................................................. 256 Implementation View ........................................................................................................................... 257 How the Stock Trader RI Works ............................................................................................................ 257 Technical Challenges ............................................................................................................................. 265

Modularity QuickStarts ............................................................................................................................. 268 Building and Running the QuickStarts .................................................................................................. 270 Walkthrough ......................................................................................................................................... 271 Implementation Details ........................................................................................................................ 275 Key Modularity Classes ......................................................................................................................... 280 Acceptance Tests .................................................................................................................................. 280

Interactivity QuickStart ............................................................................................................................. 281 Building and Running the QuickStart .................................................................................................... 282 Implementation Details ........................................................................................................................ 282 Key Interactivity Classes........................................................................................................................ 292 Acceptance Tests .................................................................................................................................. 293

MVVM QuickStart ..................................................................................................................................... 294 Building and Running the QuickStart .................................................................................................... 295 Implementation Details ........................................................................................................................ 295

Commanding QuickStart ........................................................................................................................... 302 Building and Running the QuickStart .................................................................................................... 302 Implementation Details ........................................................................................................................ 303 Acceptance Tests .................................................................................................................................. 307

UI Composition QuickStart........................................................................................................................ 308 Building and Running the QuickStart .................................................................................................... 308 Implementation Notes .......................................................................................................................... 309

7

Acceptance Tests .................................................................................................................................. 314 State-Based Navigation QuickStart ........................................................................................................... 315

Building and Running the QuickStart .................................................................................................... 316 Implementation Details ........................................................................................................................ 316 Acceptance Tests .................................................................................................................................. 325 View-Switching Navigation QuickStart ..................................................................................................... 326 Building and Running the QuickStart .................................................................................................... 327 Implementation Details ........................................................................................................................ 327 Navigation Support in the Prism Library ............................................................................................... 328 Using the Prism Library for Navigation ................................................................................................. 331 Unit and Acceptance Tests.................................................................................................................... 338 Event Aggregation QuickStart ................................................................................................................... 340 Building and Running the QuickStart .................................................................................................... 340 Implementation Details ........................................................................................................................ 341 Unit and Acceptance Tests.................................................................................................................... 344 17: Getting Started Using the Prism Library Hands-on Lab ...................................................................... 345 System Requirements ........................................................................................................................... 345 Procedures ............................................................................................................................................ 346 Task 1: Creating a Solution Using the Prism Library ............................................................................. 346 Task 2: Adding a Module....................................................................................................................... 353 Task 3: Adding a View ........................................................................................................................... 357 18: Publishing and Updating Applications Using the Prism Library Hands-on Lab................................... 361 System Requirements ........................................................................................................................... 361 Preparation ........................................................................................................................................... 361 Procedures ............................................................................................................................................ 362 Task 1: Publishing an Initial Version of the Shell Application ............................................................... 362 Task 2: Updating the Manifests to Include Dynamically Loaded Module Assemblies ......................... 369 Task 3: Deploying the Initial Version to a Client Computer .................................................................. 373 Task 4: Publishing an Updated Version of the Application and Updating the Manifests ..................... 375 Task 5: Deploying the Updated Version to a Client Computer ............................................................. 377 Bibliography .............................................................................................................................................. 378

8

Download and Setup Prism

Learn what's included in Prism 5.0 including the documentation, WPF code samples, and libraries. Additionally find out where to get the library and sample source code and the library NuGet packages. For a list of the new features, assets, and API changes, see What's New in Prism 5.0.

Documentation

Prism includes the following documentation: Developer's Guide to Microsoft Prism 5.0 on MSDN. Prism Reference Documentation on MSDN. Developer's Guide to Microsoft Prism 5.0 in .pdf format. Prism Reference Documentation in chm format.

NuGet Packages

Prism: Downloads NuGet dependency packages--position, Prism.Interactivity, Prism.Mvvm, and Prism.PubSubEvents NuGet Packages.

position: Modularity, UI Composition, Bootstrapping, Interactivity, IActiveAware, Navigation, and deprecated NotificationObject and PropertySupport.

Prism.Interactivity: Interactivity. Prism.Mvvm: The Portable Class Library for MVVM and the associated platform specific code

to support MVVM. Includes Commanding, BindableBase, ErrorsContainer, IView, and ViewModelLocationProvider. Prism.PubSubEvents: The Portable Class Library for PubSubEvents. Prism.UnityExtensions: Use these extensions to Prism to build Prism applications based on Unity. Prism.MefExtensions: Use these extensions to Prism to build Prism applications based on Managed Extensibility Framework (MEF).

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download