Finishing the Stroke
<UserControl x:Class='SilverlightApplication3.MainPage'
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
xmlns:d='http://schemas.microsoft.com/expression/blend/2008'
xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006'
mc:Ignorable='d'
d:DesignWidth='640' d:DesignHeight='480'>
<StackPanel x:Name="LayoutRoot" Background="White">
<InkPresenter x:Name="myInkPresenter" Background="Silver" Height="300" Width="300" />
</StackPanel>
</UserControl>
//File: Page.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Ink;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication3
{
public partial class MainPage : UserControl
{
private Stroke stroke = null;
public MainPage()
{
InitializeComponent();
myInkPresenter.MouseLeftButtonDown += new MouseButtonEventHandler(ipMouseLeftButtonDown);
myInkPresenter.MouseMove += new MouseEventHandler(ipMouseMove);
myInkPresenter.MouseLeftButtonUp += new MouseButtonEventHandler(ipMouseLeftButtonUp);
myInkPresenter.MouseLeave += new MouseEventHandler(ipMouseLeave);
}
public void ipMouseMove(object sender, MouseEventArgs e)
{
if (this.stroke != null)
{
this.stroke.StylusPoints.Add(
e.StylusDevice.GetStylusPoints(myInkPresenter));
}
}
public void ipMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
myInkPresenter.CaptureMouse();
this.stroke = new Stroke(e.StylusDevice.GetStylusPoints(myInkPresenter));
this.stroke.DrawingAttributes.Color = Colors.Blue;
this.stroke.DrawingAttributes.OutlineColor = Colors.White;
myInkPresenter.Strokes.Add(stroke);
}
public void ipMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
myInkPresenter.ReleaseMouseCapture();
this.stroke = null;
}
public void ipMouseLeave(object sender, MouseEventArgs e)
{
myInkPresenter.ReleaseMouseCapture();
this.stroke = null;
}
}
}
Related examples in the same category