Search Wiki:
French, German, Italian, Japanese, Korean, Russian, Simplified Chinese, Spanish, Traditional Chinese

Welcome to the Windows Presentation Foundation (WPF) documentation samples site. This site has samples that complement the WPF documentation on MSDN. These samples target Visual Studio 2010 and are organized in the following categories.

All Samples Getting Started with WPF Application Samples
WPF Windows Samples WPF Fundamentals Input and Commands
Styles Themes Threading
Controls Control Customization Layout
Data Binding Drag and Drop Packaging
Typography Brushes Geometries
Images Shapes Transformations
3-D Graphics Animations Visual Layer Programming
Globalization and Localization Migration and Interoperability

All Samples

All Samples
This download contains all of the WPF documentation samples in a single package.
Download

Getting Started with WPF

Introduction to Building WPF Applications
This sample provides an introduction to the development of a simple WPF application, and demonstrates controls, images, layout, and data binding.
Download | Getting Started with WPF
Introduction to Building WPF Applications

WPF Controls Gallery Sample
This sample shows common usage scenarios and the default rendering behavior for many user interfaces and layout controls in WPF.
Download | System.Windows.Controls Namespace
WPF Controls Gallery Sample

Application Samples

Video Viewer Demo
This sample creates a video viewing application that demonstrates styling, data binding, and data templating features.
Download | Styling and Templating
Video Viewer Demo

Data Binding Demo
This sample creates a product listing application that allows users to enter items for sale. This sample demonstrates several data binding concepts.
Download | Data Binding Overview
Data Binding Demo

Particle Effects Demo
This sample application demonstrates how to produce particle effects within a System.Windows.Controls.Viewport3D.
Download | Viewport3D Class
Particle Effects Demo

XBAP Hosting Silverlight Sample
This sample demonstrates how to host a Silverlight-based application in a XAML browser application (XBAP) and how to communicate between the host XBAP and the hosted Silverlight-based application.
Download | WPF XAML Browser Applications Overview
XBAP Hosting Silverlight Sample

WPF Windows Samples

MessageBox Sample
This sample demonstrates how to display a message box and get the message box return value.
Download | Dialog Boxes Overview
MessageBox Sample

Dialog Box Sample
This sample demonstrates how to use message boxes and common dialog boxes. This sample also shows how to create and use both modal and modeless dialog boxes.
Download | Dialog Boxes Overview
Dialog Box Sample

Notification Icon Sample
This sample demonstrates how to display an icon in the notification area.
Download | NotifyIcon Class
Notification Icon Sample

WPF Fundamentals

Height Properties Sample
This sample shows the differences among the height-related properties in WPF.
Download | How to: Set the Height Properties of an Element
Height Properties Sample

Width Properties Comparison Sample
This sample shows the differences among the width-related properties in WPF.
Download | How to: Set the Width Properties of an Element
Width Properties Comparison Sample

Input and Commands

Create a Custom RoutedCommand Sample
This sample shows how to create and use a custom System.Windows.Input.RoutedCommand.
Download | Commanding Overview
Create a Custom RoutedCommand Sample

Styles

Introduction to Styling and Templating Sample
This is a simple photo application that is designed to demonstrate how to use styling to create a visually compelling user experience.
Download | Styling and Templating
Introduction to Styling and Templating Sample

Themes

Default WPF Themes
The theme files in this section are created from the resource dictionaries containing each WPF theme and are provided as examples of how to create themes, as well as how to customize existing controls.
Download | System.Windows.Controls Namespace

Threading

Single-Threaded Application with Long-Running Calculation Sample
This sample demonstrates how to keep the UI from becoming non-responsive in single threaded application which performs a long operation.
Download | System.Windows.Threading Namespace
Single-Threaded Application with Long-Running Calculation Sample

Controls

ListView with Multiple Views Sample
This sample shows how to create a System.Windows.Controls.ListView control that displays data in multiple view modes, which include the System.Windows.Controls.GridView and other custom view modes.
Download | ListView Overview
ListView with Multiple Views Sample

TreeListView Sample
This sample shows how to create a custom TreeView that resembles the ListView when it uses the GridView.
Download | TreeView Class
TreeListView Sample

Popup Placement Sample
This sample creates a simple System.Windows.Controls.Primitives.Popup and lets the user position the System.Windows.Controls.Primitives.Popup.
Download | Popup Placement Behavior
Popup Placement Sample

Control Customization

Styling with ControlTemplates Sample
This sample shows the System.Windows.Controls.ControlTemplate examples for the most common WPF controls. If you are replacing the System.Windows.Controls.ControlTemplate of a control, these examples are the best place to get started.
Download | Styling and Templating
Styling with ControlTemplates Sample

NumericUpDown Custom Control with Theme and UI Automation Support Sample
This sample demonstrates how to create a custom control that supports theming and UI automation.
Download | Control Authoring Overview
NumericUpDown Custom Control with Theme and UI Automation Support  Sample

ColorPicker Custom Control Sample
This sample shows how to create a custom control and display it in a dialog window. This sample defines a custom color picker control that enables users to browse colors by their hue, saturation, and brightness.
Download | Dialog Boxes Overview
ColorPicker Custom Control Sample

ResizingAdorner Sample
This sample implements a simple adorner that adds resizing handles to the element to which it is applied.
Download | Adorner Class
ResizingAdorner Sample

Custom Radial Panel Sample
This sample shows how to derive a custom layout object from System.Windows.Controls.Panel that arranges its child elements in a radial pattern.
Download | Layout System
Custom Radial Panel Sample

Create a Custom Content-Wrapping Panel Sample
This sample shows how to override the default layout behavior of the System.Windows.Controls.Panel element.
Download | How to: Create a Custom Panel Element
Create a Custom Content-Wrapping Panel Sample

Layout

WPF Layout Gallery Sample
This sample provides a set of overview documents and samples that visually introduce you to the layout system in WPF.
Download | Layout System
WPF Layout Gallery Sample

Data Binding

Binding Validation Sample
This sample shows how to implement data validation on the UI layer using binding.
Download | How to: Implement Binding Validation
Binding Validation Sample

Introduction to Data Templating Sample
This sample demonstrates how to use System.Windows.DataTemplate, System.Windows.DataTrigger, and System.Windows.Controls.DataTemplateSelector to specify the presentation of your data.
Download | Data Templating Overview
Introduction to Data Templating Sample

Changing a Collection by Using IEditableCollectionView Sample
This sample uses the members that are provided by the System.ComponentModel.IEditableCollectionView interface to add and change items in a System.Windows.Controls.ListView.
Download | IEditableCollectionView Interface
Changing a Collection by Using IEditableCollectionView Sample

Sorting and Filtering Items in a View Sample
This sample shows how to use a collection view to apply a sort order and filtering.
Download | How to: Filter Data in a View
Sorting and Filtering Items in a View Sample

Drag and Drop

Drag and Drop an Object on a Canvas Sample
This example shows how to move objects on a System.Windows.Controls.Canvas using drag and drop. In addition, this sample shows how to apply an adorner and an animation to the object as it is being moved.
Download | Drag and Drop Overview
Drag and Drop an Object on a Canvas Sample

Load a Dropped File Sample
This sample will open and display the contents of a text file dropped on the sample.
Download | DataObject Class
Load a Dropped File Sample

Thumb Drag Functionality Sample
This example shows how to use a System.Windows.Controls.Primitives.Thumb to resize a System.Windows.Controls.Canvas control by responding to the System.Windows.Controls.Primitives.Thumb.DragDelta event.
Download | How to: Use a Thumb to Enable Dragging
Thumb Drag Functionality Sample

Packaging

Reading a Package Sample
This sample shows how to read content, resource, and relationship parts from a XML Paper Specification (XPS) System.IO.Packaging.Package.
Download | Documents in WPF
Reading a Package Sample

Writing a Package Sample
This sample shows how to write content, resource, and relationship parts to a XML Paper Specification (XPS) System.IO.Packaging.Package.
Download | Documents in WPF
Writing a Package Sample

Creating a Package with a Digital Signature Sample
This sample shows how to write a XML Paper Specification (XPS) package with digitally signed content, and then read and validate the signed elements.
Download | PackageDigitalSignatureManager Class
Creating a Package with a Digital Signature Sample

Typography

Advanced Text Formatting Sample
This sample shows how to create and use the Microsoft .NET Framework text engine.
Download | Advanced Text Formatting
Advanced Text Formatting Sample

Brushes

Brushes Sample
This sample shows how to paint with solid colors, gradients, images, and drawings. It shows how to use features common to all brushes, such as the System.Windows.Media.Brush.Transform, System.Windows.Media.Brush.RelativeTransform, and System.Windows.Media.Brush.Opacity properties. It also demonstrates how to animate System.Windows.Media.SolidColorBrush and System.Windows.Media.GradientBrush objects.
Download | WPF Brushes Overview
Brushes Sample

ImageBrush Sample
This sample shows how to use an System.Windows.Media.ImageBrush to paint an area with an image. It also shows how to create patterns from an image.
Download | WPF Brushes Overview
ImageBrush Sample

VisualBrush Sample
This sample shows how to use a System.Windows.Media.VisualBrush to paint an area with text, controls, and shapes. It also shows how to use a visual brush to magnify a portion of the screen and create a reflection.
Download | WPF Brushes Overview
VisualBrush Sample

Opacity Masking Sample
This sample shows how to create opacity masks and apply them to elements.
Download | DrawingBrush Class
Opacity Masking Sample

Geometries

Geometries Sample
This sample shows how to create and use geometries.
Download | Geometry Overview
Geometries Sample

Point Sample
This sample demonstrates the different operations of the System.Windows.Point structure.
Download | Point Structure
Point Sample

Vector Sample
This sample shows how to use the various methods and properties of the System.Windows.Vector structure.A list of radio buttons is created that selects the operation to perform.
Download | Vector Structure
Vector Sample

Clip Region Sample
This sample shows how to define System.Windows.UIElement.Clip regions.
Download | How to: Animate a Clip Region
Clip Region Sample

Converter Sample
This sample shows how to use the converter classes to convert an instance of a type into a string.
Download | PointConverter Class
Converter Sample

Images

ImageView Sample
This sample shows a simple image viewing utility using the System.Windows.Controls.Image and System.Windows.Media.Imaging.BitmapImage objects.
Download | Imaging Overview
ImageView Sample

Win32 Sample Codec
This sample demonstrates how to create a custom codec can be built using the unmanaged WPF Imaging Component API.
Download | Imaging Overview

Shapes

Shape Elements Sample
This sample shows how to draw by using the following System.Windows.Shapes.Shape elements:
System.Windows.Shapes.Ellipse, System.Windows.Shapes.Line, System.Windows.Shapes.Path, System.Windows.Shapes.Polygon, System.Windows.Shapes.Polyline, and System.Windows.Shapes.Rectangle.
Download | WPF Graphics, Animation, and Media Overview
Shape Elements Sample

Transformations

2-D Transforms Sample
This sample shows how to create, use, and animate two-dimensional transforms.
Download | Transforms Overview
2-D Transforms Sample

Matrix Sample
This sample shows how to use the various methods and properties of the System.Windows.Media.Matrix structure.
Download | Matrix Structure
Matrix Sample

3-D Graphics

3-D Hit Testing Sample
This sample provides information about hit testing on an animated 3-D model.
Download | How to: Hit Test in a Viewport3D
3-D Hit Testing Sample

3-D Lights Sample
This sample shows how to use the various methods and properties of the System.Windows.Media.Media3D.AmbientLight, System.Windows.Media.Media3D.DirectionalLight, and System.Windows.Media.Media3D.PointLight, objects.
Download | System.Windows.Media.Media3D Namespace
3-D Lights Sample

3-D Mesh Sample
This sample shows how to build meshes and group models to compose a 3-D scene in procedural code.
Download | Point3DCollection Class
3-D Mesh Sample

3-D Scene Sample
This sample shows how to create and draw in a 3-D scene.
Download | 3-D Graphics Overview
3-D Scene Sample

3-D Scene Animation Rotation Code Sample
This sample shows how to animate a rotation transformation on a 3-D model in procedural code.
Download | PerspectiveCamera Class
3-D Scene Animation Rotation Code Sample

3-D Solids Sample
This sample applies images to several different 3-D models and shows how to re-use application resources in building a 3-D scene.
Download | System.Windows.Media.Media3D Namespace
3-D Solids Sample

Animated Rotation Markup Sample
This sample shows how to animate a rotation transformation on a 3-D model.
Download | 3-D Transformations Overview
Animated Rotation Markup Sample

MatrixTransform3D Viewer Sample
This sample provides a 3-D scene and some basic controls to demonstrate the effects of different Matrix3D values on transformations applied to a 3-D model.
Download | 3-D Transformations Overview
MatrixTransform3D Viewer Sample

Point3D Sample
This sample shows how to use the various methods and properties of the System.Windows.Media.Media3D.Point3D structure.
Download | Point3D Structure
Point3D Sample

Point4D Sample
This sample shows how to use the various methods and properties of the System.Windows.Media.Media3D.Point4D structure.
Download | Point4D Structure
Point4D Sample

Quaternion Viewer Sample
This sample provides a 3-D scene and some basic controls to demonstrate the effects of different quaternion values on transformations applied to a 3-D model.
Download | System.Windows.Media.Media3D Namespace
Quaternion Viewer Sample

Size3D Sample
This sample shows how to use the various methods and properties of the System.Windows.Media.Media3D.Size3D structure.
Download | Size3D Structure
Size3D Sample

Vector3D Sample
This sample shows how to use the various methods and properties of the System.Windows.Media.Media3D.Vector3D structure.
Download | Vector3D Structure
Vector3D Sample

UIElement3D Sphere Sample
This sample shows how to create a Sphere class that derives from System.Windows.UIElement3D.
Download | UIElement3D Class
UIElement3D Sphere Sample

Interactive 2-D on 3-D Sample
This sample demonstrates how to place interactive 2-D content, a button in this case, on a 3D object, using the System.Windows.Media.Media3D.Viewport2DVisual3D class.
Download | Viewport2DVisual3D Class
Interactive 2-D on 3-D Sample

Handling Events in 3-D Sample
This sample demonstrates how to create 3-D objects that respond to events using the System.Windows.Media.Media3D.ContainerUIElement3D and System.Windows.Media.Media3D.ModelUIElement3D classes. In particular, this sample creates two cubes that respond to mouse-down events.
Download | UIElement3D Class
Handling Events in 3-D Sample

Animations

Animation Example Gallery
This sample shows how to animate a variety of objects, include text, 2-D transforms, and 3-D transforms. It also demonstrates splined interpolation, path animations, and custom animations.
Download | Animation Overview
Animation Example Gallery

Animating the Opacity of an Element Sample
This sample shows how to animate the System.Windows.UIElement.Opacity of an element.
Download | How to: Animate the Opacity of an Element or Brush
Animating the Opacity of an Element Sample

Animation Timing Behavior Sample
This sample shows how to specify when an animation starts, how many times it repeats, whether it accelerates or decelerates, and other timing behaviors.
Download | Timing Behaviors Overview
Animation Timing Behavior Sample

Custom Animation Sample
This sample shows how to create custom animations that simulate bouncing and other interesting effects.
Download | Custom Animations Overview
Custom Animation Sample

From, To, and By Animation Target Values Sample
This sample shows how to use the System.Windows.Media.Animation.DoubleAnimation.From, System.Windows.Media.Animation.DoubleAnimation.To, and System.Windows.Media.Animation.DoubleAnimation.By values of an animation.
Download | From/To/By Animations Overview
From, To, and By Animation Target Values Sample

KeyFrame Animation Sample
This sample shows how to use key frame animations to animate along a set of target values.
Download | Key-Frame Animations Overview
KeyFrame Animation Sample

Key Spline Animation Sample
This sample enables you to interactively adjust the key spline of a System.Windows.Media.Animation.DoubleAnimationUsingKeyFrames.
Download | Key-Frame Animations Overview
Key Spline Animation Sample

Path Animation Sample
This sample shows how to animate an object along a geometric path.
Download | Path Animations Overview
Path Animation Sample

Visual Layer Programming

Using the CompositionTarget Sample
This sample illustrates how to use System.Windows.Media.CompositionTarget object to create custom drawings or animations based on a per-frame callback.
Download | How to: Render on a Per Frame Interval Using CompositionTarget
Using the CompositionTarget Sample

Hit Test Using DrawingVisuals Sample
This sample demonstrates how to use System.Windows.Media.DrawingVisual objects to create lightweight graphics. The sample also shows how to implement hit testing at the visual object level.
Download | Using DrawingVisual Objects
Hit Test Using DrawingVisuals Sample

Hit Test with Win32 Interoperation Sample
This sample demonstrates how to use the default hit testing support in the visual layer of WPF.
Download | Hit Testing in the Visual Layer
Hit Test with Win32 Interoperation Sample

Globalization and Localization

Globalization Homepage Sample
This example demonstrates how to build and localize a Homepage.
Download | WPF Globalization and Localization Overview
Globalization Homepage Sample

LocBaml Tool Sample
This sample demonstrates how to use the LocBaml tool to parse input files to create localizable resources and generate a localized binary. The C# files build the tool and the XAML files build a DLL to use as input for the LocBaml tool.
Download | WPF Globalization and Localization Overview
LocBaml Tool Sample

Migration and Interoperability

Hosting a Windows Forms Control in WPF Sample
This sample demonstrates how to host a Windows Forms control in a WPF application.
Download | Walkthrough: Hosting a Windows Forms Control in WPF
Hosting a Windows Forms Control in WPF Sample

Hosting a Windows Forms Control in WPF by Using XAML Sample
This sample demonstrates how to host a Windows Forms control in a WPF application by using XAML.
Download | Walkthrough: Hosting a Windows Forms Control in WPF by Using XAML
Hosting a Windows Forms Control in WPF by Using XAML Sample

Hosting a Windows Forms Composite Control in WPF Sample
This sample shows you how to host a Windows Forms data-entry composite control in a WPF application. It shows how to receive events and acquire data from the control and modify the control's properties.
Download | Walkthrough: Hosting a Windows Forms Composite Control in WPF
Hosting a Windows Forms Composite Control in WPF Sample

Enabling Visual Styles in a Hybrid Application Sample
This sample shows how to enable Microsoft Windows XP visual styles on a Windows Forms control hosted in a WPF-based application.
Download | How to: Enable Visual Styles in a Hybrid Application
Enabling Visual Styles in a Hybrid Application Sample

Arranging Windows Forms Controls in WPF Sample
This sample shows how to use WPF layout features to arrange Windows Forms controls in a hybrid application.
Download | Walkthrough: Arranging Windows Forms Controls in WPF
Arranging Windows Forms Controls in WPF Sample

Data Binding in Hybrid Applications Sample
This sample shows how to bind WPF and Windows Forms controls to a common data source and display the results in a master/detail form.
Download | Walkthrough: Binding to Data in Hybrid Applications
Data Binding in Hybrid Applications Sample

Hosting a 3-D WPF Composite Control in Windows Forms Sample
This sample demonstrates how to host a WPF composite control that displays a three-dimensional (3-D) cone in a Windows Forms application.
Download | Walkthrough: Hosting a 3-D WPF Composite Control in Windows Forms
Hosting a 3-D WPF Composite Control in Windows Forms Sample

Hosting a WPF Composite Control in Windows Forms Sample
This sample demonstrates how to host a WPF data-entry composite control in a Windows Forms application. It shows how to receive events and acquire data from the control and modify the control's properties.
Download | Walkthrough: Hosting a WPF Composite Control in Windows Forms
Hosting a WPF Composite Control in Windows Forms Sample

Mapping Properties Using the ElementHost Control Sample
This sample shows how to use the System.Windows.Forms.Integration.ElementHost.PropertyMap property to map Windows Forms properties to corresponding properties on a hosted WPF element.
Download | Walkthrough: Mapping Properties Using the ElementHost Control
Mapping Properties Using the ElementHost Control Sample

Mapping Properties Using the WindowsFormsHost Element Sample
This sample shows how to use the System.Windows.Forms.Integration.WindowsFormsHost.PropertyMap property to map WPF properties to corresponding properties on a hosted Windows Forms control.
Download | Walkthrough: Mapping Properties Using the WindowsFormsHost Element
Mapping Properties Using the WindowsFormsHost Element Sample

Localizing a Hybrid Application Sample
This sample shows how to localize WPF elements in a Windows Forms-based hybrid application.
Download | Walkthrough: Localizing a Hybrid Application
Localizing a Hybrid Application Sample

Hosting a Win32 HWND in WPF Sample
This sample shows how to put an hwnd inside a WPF application.
Download | WPF and Win32 Interoperation
Hosting a Win32 HWND in WPF Sample

Hosting a Win32 ListBox Control in WPF Sample
Hosts a Win32 ListBox control in a WPF application. This sample shows how to create and host the control, and how to send and receive messages.
Download | Walkthrough: Hosting a Win32 Control in WPF
Hosting a Win32 ListBox Control in WPF Sample

Hosting WPF Content in Win32 Sample
This sample hosts WPF content in a Win32 window. The sample shows how to create and host the control, and how to handle communication between the control and the host window.
Download | Walkthrough: Hosting WPF Content in Win32
Hosting WPF Content in Win32 Sample

Win32 Clock Interoperation Sample
This sample demonstrates how to host a WPF clock inside of a Win32 application.
Download | Walkthrough: Hosting a WPF Clock in Win32
Win32 Clock Interoperation Sample
Last edited Aug 31 2010 at 2:32 AM  by rlyon, version 66
Comments
LucSkiAilleurs wrote  May 20 2010 at 8:51 AM  
Hi,

Very thanks for this tutos....

But when we are starting WPF development, there are no context for the files like Themes. How create them in Visual Studio.

Where put them in a solution.

It will be better if you can put some screenshots of the composition of the solution in visual studio

Bests regards

Ronsher1 wrote  Dec 27 2010 at 8:37 AM  
Hi,

I'm missing more threading samples that are mentioned at "Threading Model" (http://msdn.microsoft.com/en-us/library/ms741870.aspx).
Specifically - "Handling a Blocking Operation with a Background Thread", "Multiple Windows, Multiple Threads"

Thanks,
Ron

orent wrote  Jan 28 2011 at 8:37 AM  
Hi
There is not imlemntation of InInitializeComponent function in all samples
therfor I can't to compile the samples

cosmin2509 wrote  Jan 28 2011 at 3:09 PM  
H Orent.
I had the same problem so i did some research and this is happening because we don't have visual studio 2010 - framework 4.0.
Those example are using System.Xaml that can be found only on framework 4.0 . I will install visual studio 2010 later today.

WDS wrote  Apr 1 2011 at 1:42 PM  
Are are needed for anyone build any kind of application::::::::::
The base knowledge required for build applications is how to archive these operations:

1.Understand Where\When\How to write code.At its base for Procedures,Functions,Variables.
2.Work with variables: String,Object references.
3.Understand how to operations for IF,WHILE,CASE
4.Access to a text file and being able for open\read\write\save to the file.
5.Manage resources for Store,Load,Apply,Destroy.
6.Operations to control user interface: Move Controls,Change Controls,Manage Controls.

7.Explanation about every aspect of code for knowledge about how to type it on editor.

Updating...
Page view tracker