Skip to content

Files

Latest commit

 

History

History
 
 

WpfTraining

WPF Training

This folder contains samples that I use during WPF Trainings. Most samples are as small as possible to demonstrate a certain concept of WPF.

XAML Introduction

These samples focus on the basic concepts of XAML. They do not focus on WPF, they should help to understand the XAML declarative programming language.

Behind the scenes

Element Naming

I use these samples to demonstrate naming of elements (x:Name) in WPF XAML files.

  • 01 ElementNaming shows element naming during compile time.

  • 02 ElementNaming Runtime shows how to use the LogicalTreeHelper class to bind named elements to properties. This is useful for scenarios in which WPF XAML is loaded during runtime.

Application Definition Files

This sample demonstrates how to add a custom object to an App.xaml file.

WPF XAML Hello World

These are not the classical Hello World sample for WPF. I use them during trainings to show what is happening when XAML files are compiled.

  • 04 Hello World shows that XAML pages do not necessarily contain WPF classes. This sample generates a class using XAML that has nothing to do with WPF. It is used in a console application.

  • 05 Hello World Runtime is a variant of the first sample. It shows how to load the XAML file during runtime.

  • 06 Hello World Embedded Code is another variant of the sample. It shows how to embed C# code in XAML. Note that this is not a recommended approach. However, it typically helps to understand what's going on in the background during XAML compilation.

XAML Features

This sample demonstrates different aspects of the XAML programming language. It covers the following topics:

  • x:Array
  • x:Class
  • x:Code
  • Page Functions
  • {x:Null}
  • xml:space="preserve"
  • {x:Static}
  • Content Properties
  • x:XData
  • Custom XML Namespaces (XmlnsDefinition)

TV Listings

I use this sample in WPF trainings to show how to implement XAML concepts like markup extensions, type converters, content properties, etc. in custom classes.

Data Bindings

Using Dependency Properties

This set of stand-alone XAML pages demonstrates various applications of dependency properties like resources, data binding, styling, etc. You can run the XAML pages e.g. in Internet Explorer.

Free Space Watcher

I use this sample in WPF trainings to demonstrate how to implement custom dependency properties. 02 FreeSpaceWatcher - Step 1 is a simple implementation while 03 FreeSpaceWatcher - Step 2 adds a user control with dependency properties. 04 FreeSpaceWatcher - Step 3 finally adds a timer and multiple UI threads in a single WPF application.

Data Binding Scenarios

This sample contains various small examples for data bindings. It covers:

  • ElementName bindings
  • Binding to XML using XPath
  • Binding to objects in resources
  • OneWayToSource
  • Binding to the result of a method using ObjectDataProvider
  • Binding to collections
  • Binding to ADO.NET
  • Binding validation
  • Use of UpdateSourceTrigger
  • Use of CompositeCollection
  • Binding and notification (INotifyPropertyChanged, ObservableCollection, etc.)

UI Design With WPF and XAML

Simple XAML Sources

This set of stand-alone XAML pages demonstrates some basics about WPF UI design (e.g. grid, flow document, canvas, panels, etc.).

Adorner

I use this sample in trainings if people are interested in how to use adorners.

Styles and Templates

This is again a larger sample. It consists of many pages each demonstrating a different aspect of styling and templating. It covers for instance:

  • Styles (default styles, named style, style inheritance, etc.)
  • Triggers (data triggers, event triggers, etc.)
  • Simple animations
  • Data templates
  • Data template selector
  • Control templates

Step Panel

This sample demonstrates a very simple custom panel. I use it to discuss the role of MeasureOverride and ArrangeOverride.

Lookless Control

This sample has been created by my colleague Karin. It shows how to implement a custom control with a control templates that you can override.