English
Summary
Conclusions
WPF is a desktop application technology for Windows in which the interface is described with XAML markup and the behavior with C# code. XAML elements become objects, attributes become properties and event handlers, and the system renders a retained element tree through DirectX in device-independent units. The Grid, StackPanel, DockPanel, WrapPanel, UniformGrid, and Canvas panels arrange elements according to their desired size, so the interface adapts to the window, the font, and the scale. Routed events travel through the element tree by tunneling and bubbling, which makes it possible to handle the events of a group of elements with one handler and to filter input. Dependency properties support inheritance, styles, animation, data binding, and value source precedence; custom controls are built on them. Commands, resources, dialogs, the Live Visual Tree tools, and XAML Hot Reload make WPF a convenient foundation for applications in which (Topic 13) the logic is then separated from the interface with data binding and the MVVM pattern.
Self-check questions
- How does WPF differ from Windows Forms? What does retained-mode rendering mean?
- Which assemblies and components make up the WPF architecture? Which of them is unmanaged, and why?
- Which files does the WPF Application template create? What roles do
x:Class,partial, andInitializeComponentplay? - How do XAML elements and attributes correspond to C# objects and properties? What is a type converter?
- How does the logical tree differ from the visual tree?
- What capabilities do Live Visual Tree, Live Property Explorer, and XAML Hot Reload provide?
- How do the
Auto, numeric, and*sizes differ in aGrid? How do you add aGridSplitter? - When do you use
StackPanel,WrapPanel,DockPanel,UniformGrid, andCanvas? - What is the content model? How does
ContentControldiffer fromItemsControl? - What event routing strategies exist? How does
Sourcediffer fromOriginalSource? - How do you register a dependency property? Why must the wrapper contain no logic?
- In what order of precedence is the value of a dependency property determined? What does
ClearValuedo? - How do built-in commands,
CommandBinding, andCanExecutework? - How do you show a modal window and get a result? What are
Owner,IsDefault, andIsCancelfor? - How do you enable the Fluent theme, and why does accessing
ThemeModein code give error WPF0001?
Useful links
- WPF documentation: https://learn.microsoft.com/dotnet/desktop/wpf/
- WPF overview: https://learn.microsoft.com/dotnet/desktop/wpf/overview/
- Creating an application in Visual Studio: https://learn.microsoft.com/dotnet/desktop/wpf/get-started/create-app-visual-studio
- XAML in WPF: https://learn.microsoft.com/dotnet/desktop/wpf/xaml/
- Layout: https://learn.microsoft.com/dotnet/desktop/wpf/advanced/layout
- Routed events: https://learn.microsoft.com/dotnet/desktop/wpf/events/routed-events-overview
- Dependency properties: https://learn.microsoft.com/dotnet/desktop/wpf/properties/dependency-properties-overview
- What's new in WPF for .NET 10: https://learn.microsoft.com/dotnet/desktop/wpf/whats-new/net100