public MainPage()
{
InitializeComponent();
Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
}
// preXArray and preYArray are used to store the start point
// for each touch point. currently silverlight support 4 muliti-touch
// here declare as 10 points for further needs.
double[] preXArray = new double[10];
double[] preYArray = new double[10];
/// <summary>
/// Every touch action will rise this event handler.
/// </summary>
void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
int pointsNumber = e.GetTouchPoints(drawCanvas).Count;
TouchPointCollection pointCollection = e.GetTouchPoints(drawCanvas);
for (int i = 0; i < pointsNumber; i++)
{
if (pointCollection[i].Action == TouchAction.Down)
{
preXArray[i] = pointCollection[i].Position.X;
preYArray[i] = pointCollection[i].Position.Y;
}
if (pointCollection[i].Action == TouchAction.Move)
{
Line line = new Line();
line.X1 = preXArray[i];
line.Y1 = preYArray[i];
line.X2 = pointCollection[i].Position.X;
line.Y2 = pointCollection[i].Position.Y;
//pen = new Pen(Brushes.DeepSkyBlue, 4);
//e.Graphics.DrawLine(pen, 10, 120, 220, 120);
//pen.Dispose();
line.Stroke = new SolidColorBrush(Colors.Black);
line.Fill = new SolidColorBrush(Colors.Black);
drawCanvas.Children.Add(line);
preXArray[i] = pointCollection[i].Position.X;
preYArray[i] = pointCollection[i].Position.Y;
}
}
}