Pruthviraj Mohite

Pruthviraj Mohite

  • NA
  • 25
  • 5.2k

_touchPoint.TouchDevice.Capture(this.canvas1);

May 15 2014 3:06 AM

I want to take input dynamically by using the touch event for that I used this code

using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;

namespace CallApp
{
public partial class MainPage : Microsoft.Phone.Controls.PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
Touch.FrameReported += new TouchFrameEventHandler(Touch_FrameReported);
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}

Point pt1, pt2 = new Point();


void Touch_FrameReported(object sender, TouchFrameEventArgs e)
{
if (this.canvas1 != null)
{
foreach (TouchPoint _touchPoint in e.GetTouchPoints(this.canvas1))
{
if (_touchPoint.Action == TouchAction.Down)
{
// Clear the canvas and capture the touch to it.
this.canvas1.Children.Clear();
_touchPoint.TouchDevice.Capture(this.canvas1);
}

else if (_touchPoint.Action == TouchAction.Move && e.GetPrimaryTouchPoint(this.canvas1) != null)
{
// This is the first (primary) touch point. Just record its position.
if (_touchPoint.TouchDevice.Id == e.GetPrimaryTouchPoint(this.canvas1).TouchDevice.Id)
{
pt1.X = _touchPoint.Position.X;
pt1.Y = _touchPoint.Position.Y;
}

// This is not the first touch point. Draw a line from the first point to this one.
else if (_touchPoint.TouchDevice.Id != e.GetPrimaryTouchPoint(this.canvas1).TouchDevice.Id)
{
pt2.X = _touchPoint.Position.X;
pt2.Y = _touchPoint.Position.Y;

Line _line = new Line();
_line.Stroke = new RadialGradientBrush(Colors.White, Colors.Black);
_line.X1 = pt1.X;
_line.X2 = pt2.X;
_line.Y1 = pt1.Y;
_line.Y2 = pt2.Y;
_line.StrokeThickness = 2;
this.canvas1.Children.Add(_line);
}
}

else if (_touchPoint.Action == TouchAction.Up)
{
// If this touch is captured to the canvas, release it.
if (_touchPoint.TouchDevice.Captured == this.canvas1)
{
this.canvas1.ReleaseTouchCapture(_touchPoint.TouchDevice);
}
}
}
}
}
// Sample code for building a localized ApplicationBar
//private void BuildLocalizedApplicationBar()
//{
// // Set the page's ApplicationBar to a new instance of ApplicationBar.
// ApplicationBar = new ApplicationBar();

// // Create a new button and set the text value to the localized string from AppResources.
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);

// // Create a new menu item with the localized string from AppResources.
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
}
}

But it giving error at

if (_touchPoint.TouchDevice.Captured == this.canvas1)
{
this.canvas1.ReleaseTouchCapture(_touchPoint.TouchDevice);
}

That missing Some Assemblies or Directive

Please Help..!!