This folder contains samples that I use during WPF Trainings. Most samples are as small as possible to demonstrate a certain concept of WPF.
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.
I use these samples to demonstrate naming of elements (x:Name) in WPF XAML
files.
-
01 ElementNamingshows element naming during compile time. -
02 ElementNaming Runtimeshows how to use theLogicalTreeHelperclass to bind named elements to properties. This is useful for scenarios in which WPF XAML is loaded during runtime.
This sample demonstrates how to add a custom object to an App.xaml file.
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 Worldshows 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 Runtimeis a variant of the first sample. It shows how to load the XAML file during runtime. -
06 Hello World Embedded Codeis 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.
This sample demonstrates different aspects of the XAML programming language. It covers the following topics:
x:Arrayx:Classx:Code- Page Functions
{x:Null}xml:space="preserve"{x:Static}- Content Properties
x:XData- Custom XML Namespaces (
XmlnsDefinition)
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.
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.
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.
This sample contains various small examples for data bindings. It covers:
ElementNamebindings- 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.)
This sample contains a typical data entry form covering various validation aspects. Examples of topics in this sample:
- Custom binding
ValidationRule - Tooltips with error messages
- Error indicators with
AdornedElementPlaceholder - Validation in converters
- Implenenting
IDataErrorInfo
This set of stand-alone XAML pages demonstrates some basics about WPF UI design (e.g. grid, flow document, canvas, panels, etc.).
I use this sample in trainings if people are interested in how to use adorners.
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
This sample demonstrates a very simple custom panel. I use it to discuss the role of
MeasureOverride and ArrangeOverride.
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.