WPF and MVVM: Advanced Model Treatment
In this course, you learn how to use Model-wrappers in your MVVM-application for several scenarios: to highlight changed fields, to highlight invalid fields, to display validation errors, to enable the save button only if there are changes, and much more.
What you'll learn
In many modern architectures, your client-application just receives simple Models from the server. These Models often don't have the logic you need in your application. It starts already with the missing information if the Model is changed or not. Without that information, you can't enable or disable the save-button based on the fact if the user has changed the Model or not. This is just one problem that is solved by the powerful Model-wrappers that we create in this course. These Model-wrappers will contain the typical functionality you need in your application: change notification, change tracking, and validation. You learn how to build these Model-wrappers by using Test Driven Development (TDD). And, as this course is about WPF and MVVM, you learn how to use the Model-wrappers in your MVVM-application. You learn how to highlight changed fields with a different background-color, how to display the original value of a changed field in the tooltip, how to highlight invalid fields, how to display validation errors, how to enable the save button only if there are changes, how to check for changes when closing a tab or even the application, how to reset the Model to its original state, and much more. Throughout this course, you learn how to extend a typical MVVM-based WPF-application called FriendStorage with all this functionality.
Table of contents
- Introduction 3m
- Create the FriendWrapper 7m
- Set and Get Simple Model-properties 3m
- Notify About Changes of Simple Properties 6m
- Refactor Common Logic into a Base-class 2m
- Use Reflection to Set and Get Property-values 6m
- Notify About Changes of Complex Properties 7m
- Notify About Changes of Collection-properties 3m
- Initialize the Wrapper-collection 3m
- Keep the Wrapper- and the Model-collection in Sync 8m
- Integrate the FriendWrapper into FriendStorage 5m
- Summary 2m
- Introduction 4m
- Track Simple Properties 2m
- Get the Original Value of a Simple Property 7m
- Get the Changed-state of a Simple Property 7m
- Refactor the Tracking Code with C# 6.0 Features 3m
- Get the Changed-state of the FriendWrapper 6m
- Accept Changes for Simple Properties 6m
- Reject Changes for Simple Properties 5m
- Track Complex Properties 9m
- Track Collection-properties 10m
- Use the ChangeTrackingCollection in the FriendWrapper 6m
- Fix the Collection-sync in the ModelWrapper 5m
- The Change Tracking Use Cases in FriendStorage 1m
- FriendStorage: Enable and Disable the Save-button 5m
- FriendStorage: Check for Changes When Closing a Tab 5m
- FriendStorage: Reset the Friend to Its Original State 3m
- Summary 1m
- Introduction 4m
- Display Changes in the TextBox 6m
- Refactor Logic into a Common TextBox Style 9m
- Bind the ChangeBehavior-properties Dynamically 12m
- Display Changes in the CheckBox 3m
- Create a Base Style to Display Changes 2m
- Display Changes in the DatePicker 2m
- Original Value Conversion in the ChangeBehavior 4m
- Convert the Original Value of the DatePicker 4m
- Set the Original Value Converter in a Style 6m
- Display Changes in the ComboBox 2m
- Convert the Original Value of the ComboBox 5m
- Display Changes in the DataGrid 6m
- Create the Element Styles Dynamically 4m
- Master Added and Removed Items 4m
- Display Changes in the Tab-header 5m
- Cancel the Closing of the FriendStorage-application 5m
- Summary 2m
- Introduction 2m
- The Interface INotifyDataErrorInfo 2m
- Implement INotifyDataErrorInfo in a Base Class 5m
- Add Validation-tests for the FirstName-property 3m
- Using Data Annotations 4m
- Validate the FirstName-property with Data Annotations 6m
- Add an IsValid-property to the ModelWrapper 4m
- Use the IsValid-property to Enable the Save-button 3m
- Validate the Full FriendWrapper 9m
- The IsValid-property of the FriendWrapper 2m
- Add the IValidatableTrackingObject-interface 6m
- IsValid and Complex-properties 5m
- IsValid and Collection-properties 6m
- Validate on Class-level with IValidatableObject 3m
- Every Developer Should Have an Email 5m
- Initialize Correctly Before Validation 3m
- Validation Attributes and IValidatableObject 3m
- Summary 2m
- Introduction 1m
- Validation Errors in the User Interface 4m
- Highlight Invalid Fields 3m
- Display the Error in the Tooltip 3m
- Define a Custom Error Template 6m
- Fix the Error Layout for the CheckBox 1m
- Use the Error Template for the DataGrid 4m
- Display Errors in Data Grid Cells 5m
- Avoid Validation for Specific Bindings 4m
- Highlight the Tab-header 2m
- Summary 3m
- Introduction 2m
- T4 Basics 2m
- Add a T4 Template to Generate the Model-wrappers 5m
- Install an Extension for T4 Syntax Highlighting 1m
- Generate a Wrapper-class for Each Model 4m
- Create One File per Model-wrapper 3m
- Generate Usings, Namespace, and Constructor 1m
- Generate Simple Properties 3m
- Support Generic Types like Nullable 2m
- Generate Complex-properties 2m
- Generate Collection-properties 3m
- Initialize Complex-properties 5m
- Initialize Collection-properties 3m
- Create Validation Logic in Partial Classes 5m
- The Final FriendStorage-application 2m
- Course Summary 2m