Introduction to Windows programming with WPF. In this module students are introduced to Windows Presentation Foundation (WPF), and how this framework can be used to build state of the art applications. Building state of the art applications requires the input of designers for building great visualizations.
Building Windows Applications with WPF
Who should attend this course?
Participants of this course need to have a good understanding of the .NET (Core) platform and have a good knowledge of C# or VB.NET.
This course will teach you how to build business applications with Windows Presentation Foundation on top of .NET framework and .NET 5. You will learn to create functional and attractive user interfaces using XAML. Since most business applications are data-driven, you will learn how to handle data using Entity Framework Core and how to consume data from web services. Furthermore, you’ll get acquainted with the MVVM pattern, making your code easier to maintain and test.
Introduction to Windows programming with WPF
In this module students are introduced to Windows Presentation Foundation (WPF), and how this framework can be used to build state of the art applications. Building state of the art applications requires the input of designers for building great visualizations. Now developers and designers can work together on the same application.
- Introduction to the WPF application
- WPF Architecture
- Designer/Developer productivity: declarative XAML
- The Visual Studio Designer
XAML is the UI-language important for developers using the Microsoft developer stack. This module teaches students how to use the XAML language for building all kinds of applications, focusing on WPF.
- What is XAML?
- XAML versus Code
- Looking at XAML basic syntax
- Understanding XAML attached properties
- Nesting controls
- The Content property
- LAB: Working with XAML
XAML can be extended for your own custom purposes. In this case you need to understand following topics.
- Extending XAML through markup extensions
- Understanding CLR and Xml namespace mapping
- Naming elements
Developers and Designers Collaboration
In a perfect world, any developer is a great designer. Unfortunately this is not the case. XAML allows for a clean separation between designing and developing.
- Developers versus designers
- Visual Studio as a development tool
- Blend as a designing tool
- Overview of Blend
This module gives you an overview of what kinds of controls are available and how to compose them together.
- Examining the Class Hierarchy
- Tweaking the UI with transforms
- The power of composability
- Content controls, Container controls, Header controls, Item controls
- Range controls, Using Text controls
- Understanding dependency properties
- Routed events
Introduction to WPF Layout
Display hardware becomes more and more diverse: big screens, small screens, high and low resolutions, adaptable font size. This does require some special up-front design. In this module students will learn how to build applications that run with all kinds of resolutions and fonts.
- Look at WPF layout capabilities
- Absolute layout using Canvas
- Using StackPanel, WrapPanel and DockPanel
- The do-it-all panel: Grid
- Tweaking using panel attached properties
- LAB: Building a layout with XAML and Visual Studio
Reusability with WPF Resources
Developers have always used specially built controls to re-use some of their work. WPF has re-use built in, so in this module students will learn how to re-use objects for their applications.
- Re-using objects through resources
- Resource inheritance
- Static resources
- Dynamic resources
- Resources and code-behind Merging Resource Dictionaries
- LAB: Creating some resources with Visual Studio
End users should easily see when an element on your UI is interactive, or when a new element has been added to your window. These things can easily be accomplished by WPF Animations, which greatly improves the user experience. In this module students will learn how provide feedback to the user using animations.
- What are animations?
- Working with storyboards
- Animations in code
- Creating animations in Blend
Principles of WPF Styles, Triggers and Templates
Professionally built web sites use cascading style sheets (.css) to quickly change the look and feel of the site. WPF takes this to the next level with styles and templates. In this module students will learn how to quickly customize their whole application with styles and templates.
- Why we need styles
- WPF look-less controls
- Example: Restyling a ListBox
- Intro to templates
- LAB: Create a button template with Blend
Entity Framework Core
With .NET 5 also comes a while new Entity Framework Core. A new implementation of EF, which can run cross-platform, on Windows, Mac and Linux.
- Differences with .NET 4.x Entity Framework
- Scaffolding your project from an existing database
- Understanding the generated code
- Interacting with the database with LINQ
- LAB: Scaffolding your model from an existing database
Using WPF Data Binding
Once the data is retrieved, we need to display it to the user and allow changes to be validation and captured efficiently. In this module students will learn how to use data binding to accomplish this.
- The need for data binding
- Binding in code and markup
- Introduction to simple data binding
- Converting data for data binding
- Introduction to complex data binding
- Understanding Source and DataContext
- Visual data binding with the Visual Studio Data Sources window
- LAB: Databinding to data with a parent-child relationship
User input needs to be validated. Are all required properties provided? Do the values match the format? WPF offers several options for validation that are explored in the following chapter.
- Validation Rules
- Custom Feedback
The Visual State Manager and Custom Controls
When customizing an interactive element for your UI, you need to specify the look and feel in all circumstances. The Visual State Manager is a mediator that allows changing styles and templates based on certain conditions. In this module students will learn how set up and use the Visual State Manager.
- What is the Visual State Manager?
- Parts, states, transitions and state groups
- Responding to state changes
- Custom Control with the Visual State Manager
- Using the Visual State Manager for responsive Layout
- Using the Visual State Manager in Blend
- LAB: Customizing a control with Visual State Manager
More loose coupling using dependency injection
When writing code, you have to make sure you are not introducing unnecessary dependencies on other objects. Dependencies will just cost you on the long run since they are harder to maintain, not easily testable, exchangeable, … . If you need to depend on another, then depend on the interface. Interfaces describe the dependency, but do not force it. Now, you don’t want those dependencies to be filled hard coded and this is where dependency injection (DI) can help you. Dependency injection can help you at runtime dynamically deciding which implementations to plug into the dependencies.
- What is tight coupling and how to prevent it?
- Using Inversion of Control (IoC) containers.
- Constructor and Property injection.
- Microsoft.Extensions.DependencyInjection as an example.
Introduction to the MVVM pattern
MVVM is a version of the MVC pattern designed specifically for WPF, which is heavily relies on Data Binding
- What is the MVVM pattern?
- Using commands instead of event handling
- Defining the model
- Adding the ViewModel
- Binding the View to the ViewModel
- LAB: Adding a View and ViewModel to a WPF application
“If this then that”, that’s what behaviors are all about. It allows you to set up new functionality for an existing control in a declarative way.
- Built-in Behaviors
- Custom Behavior
Introducing ASP.NET Web API
This part will show students how to create and consume web services with Web API.
- REST services
- CRUD operations
- Feature Overview
Consuming a ASP.NET Web API REST service with HttpClient
- HttpClient and WebHttpRequest Class
- JSON Serialization and Deserialization
- LAB: Consuming a REST service from WPF
Deploying your WPF Windows Applications
This module will show students how to deploy their WPF application
- Using XCOPY deployment
- Using Click-Once
- Using an Installer