Your first WPF Drawing Application

In this lab, you will build a WPF application that allows you to draw geometries.

1. Start Microsoft Visual Studio 2008 from Start | All Programs | Microsoft Visual Studio 2008.

2. Create a new WPF project. In Visual Studio select File | New | Project. In the New Project Dialog select Visual C# | Windows in the tree view on the left, and select WPF Application (make sure that .NET Framework 3.5 is selected in the drop-down list at the top right of the dialog box).


3. In the XAML editor, change the Title property of the Window element to WPF Viewer.

4. Add an Ink Canvas to the Window and name it DrawingPad. To do this, add the following code (shown in bold) into the Grid element.

<Grid >

<Border BorderBrush=”Gray” BorderThickness=”1″ >

<InkCanvas Name=”DrawingPad” />



5. Add an event handler for the StrokeCollected event by writing code in the XAML editor (this should generate the event handler method as well). At this point, your XAML code should look like this.


<Window x:Class=” WPFViewer.Window1″



Title=”WPF  Viewer” Height=”300″ Width=”300″>

<Grid >

<Border BorderBrush=”Gray” BorderThickness=”1″ >

<InkCanvas Name=”DrawingPad” StrokeCollected=”DrawingPad_StrokeCollected” />





6. Press F5 to run the application and draw some shapes on the Ink Canvas.


7. Close the application.