WPF – Getting Started

Simple Getting started WPF Example code that uses the InkCanvas control.

XAML code:

<Window x:Class="InkCanvasWpfApplication.InkCanvasTest"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Ink Canvas" Height="450" Width="600" Background="LightBlue" >
    <Grid>
        <InkCanvas Height="Auto" HorizontalAlignment="Stretch" Margin="9,9,9,68" Name="inkCanvas1" VerticalAlignment="Stretch" Width="Auto" Background="LightYellow"/>
        <Button Content="Clear" Height="23" HorizontalAlignment="Left" Margin="50,365,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
        <Button Content="Close" Height="23" HorizontalAlignment="Left" Margin="477,365,0,0" Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    </Grid>
</Window>

Code behind C# Code:

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.inkCanvas1.Strokes.Clear();            
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

 

References: http://msdn.microsoft.com/en-us/library/bb820878%28v=vs.90%29.aspx