WPF API Documentation
This documentation provides an overview of the core APIs for Windows Presentation Foundation (WPF). WPF is a powerful UI framework for building Windows desktop applications. It offers a rich set of features for creating visually stunning and highly interactive user experiences.
Namespace: System
The fundamental building blocks of .NET applications.
DependencyObject
The base class for most WPF objects that support the WPF property system. This is the foundation for many WPF features, including data binding, styling, and animation.
Key Features:
- Supports Dependency Properties, which enable advanced property behaviors.
- Can be a target for data binding.
- Provides the foundation for WPF's property system.
Namespace: System.Windows
Contains fundamental types and classes used throughout WPF.
Visual
The base class for all WPF objects that can be rendered. It provides the drawing context and supports the visual tree.
Key Features:
- Represents elements that can be drawn on the screen.
- Forms the basis of the visual tree.
- Enables hit testing and rendering.
Namespace: System.Windows.Controls
Contains the core UI controls and elements used to build user interfaces.
Control
The base class for all Windows Presentation Foundation (WPF) controls. It provides the basic functionality for controls, such as default template, focus handling, and keyboard navigation.
Key Features:
- Foundation for interactive UI elements.
- Supports templates for visual customization.
- Handles user input events.
Button
Represents a clickable button control.
Events:
- Click: Fired when the button is clicked.
Common Properties:
Content
: The content displayed by the button.Command
: The command to execute when the button is clicked.
TextBlock
Displays a block of text. It supports basic text formatting and inline elements.
Common Properties:
Text
: The string content to display.FontSize
: The size of the font.Foreground
: The color of the text.
Grid
A flexible layout panel that arranges elements in rows and columns.
Common Properties:
RowDefinitions
: Defines the rows in the grid.ColumnDefinitions
: Defines the columns in the grid.
Usage:
<Grid RowDefinitions="Auto,*" ColumnDefinitions="*,Auto">
<!-- Row 0, Column 0 -->
<TextBlock Grid.Row="0" Grid.Column="0" Text="Header"/>
<!-- Row 1, Column 1 -->
<TextBlock Grid.Row="1" Grid.Column="1" Text="Content"/>
</Grid>
Namespace: System.Windows.Input
Provides types for handling input, commands, and gestures.
Key
An enumeration that specifies keyboard keys. Used in keyboard event arguments.
Common Values:
Key.Enter
Key.Space
Key.A
Key.Escape
MouseButton
An enumeration that specifies mouse buttons. Used in mouse event arguments.
Common Values:
MouseButton.Left
MouseButton.Right
MouseButton.Middle
Namespace: System.Windows.Media
Contains types for graphics, multimedia, and visual elements.
Brush
The abstract base class for all brush types used to paint shapes, backgrounds, and text.
SolidColorBrush
A brush that paints an area with a solid color.
Constructor:
Common Properties:
Color
: Gets or sets the color of the brush.
Usage:
<TextBlock Text="Hello WPF" Foreground="Blue"/>
<!-- Equivalent C# -->
<TextBlock Text="Hello WPF" Foreground="{StaticResource BlueBrush}"/>
<!-- Resource Dictionary -->
<SolidColorBrush x:Key="BlueBrush" Color="Blue"/>
Key Concepts
Dependency Properties
A property system that extends the standard .NET property system. Dependency properties support features like data binding, styling, animation, and property value inheritance. They are declared using DependencyProperty
objects and registered with the WPF property system.
Routed Events
An event handling system that allows events to traverse the element tree. Events can be routed either directly, bubbling up from child to parent, or tunneling down from parent to child. This enables a single event handler to manage an event for multiple elements.
Data Templates
Used to define the visual structure of data. DataTemplates allow you to specify how data objects should be represented in the UI, enabling flexible data binding and customization of control presentation.