When Moving touch on Window Touch Move of Window is called but when touch move reaches Child (Ellipse)
Touch Move event is not fired But I atleast I want to identify if the Touch is on Ellipse or not. as it it works on mouse move
This is my Xaml code
<Window x:Class="TouchEvent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" IsManipulationEnabled="True" TouchMove="Window_TouchMove">
<Canvas Name="MainCanvas" Height="350" Width="525" Background="Gray" >
<!--
The ellipse that will be dragged around.
The Top and Left attributes must be set
or Canvas.GetTop and Canvas.GetLeft will return NaN.
-->
<Ellipse IsManipulationEnabled="True"
Name="DragEllipse"
Canvas.Top="0" Canvas.Left="0"
Fill="Red"
Width="100" Height="100"
TouchDown="DragEllipse_TouchDown"
TouchMove="DragEllipse_TouchMove"
TouchLeave="DragEllipse_TouchLeave"
>
</Ellipse>
</Canvas>
</Window>
This is my .CS Code
// Declare the global variables.
TouchDevice ellipseControlTouchDevice;
Point lastPoint;
private void DragEllipse_TouchDown(object sender, TouchEventArgs e)
{
// Capture to the ellipse.
e.TouchDevice.Capture(this.DragEllipse);
// Remember this contact if a contact has not been remembered already.
// This contact is then used to move the ellipse around.
if (ellipseControlTouchDevice == null)
{
ellipseControlTouchDevice = e.TouchDevice;
// Remember where this contact took place.
lastPoint = ellipseControlTouchDevice.GetTouchPoint(this.MainCanvas).Position;
}
// Mark this event as handled.
e.Handled = true;
}
private void DragEllipse_TouchMove(object sender, TouchEventArgs e)
{
if (e.TouchDevice == ellipseControlTouchDevice)
{
// Get the current position of the contact.
Point currentTouchPoint = ellipseControlTouchDevice.GetTouchPoint(this.MainCanvas).Position;
// Get the change between the controlling contact point and
// the changed contact point.
double deltaX = currentTouchPoint.X - lastPoint.X;
double deltaY = currentTouchPoint.Y - lastPoint.Y;
// Get and then set a new top position and a new left position for the ellipse.
double newTop = Canvas.GetTop(this.DragEllipse) + deltaY;
double newLeft = Canvas.GetLeft(this.DragEllipse) + deltaX;
Canvas.SetTop(this.DragEllipse, newTop);
Canvas.SetLeft(this.DragEllipse, newLeft);
// Forget the old contact point, and remember the new contact point.
lastPoint = currentTouchPoint;
// Mark this event as handled.
e.Handled = true;
}
}
private void DragEllipse_TouchLeave(object sender, TouchEventArgs e)
{
// If this contact is the one that was remembered
if (e.TouchDevice == ellipseControlTouchDevice)
{
// Forget about this contact.
ellipseControlTouchDevice = null;
}
// Mark this event as handled.
e.Handled = true;
}
private void Window_TouchMove(object sender, TouchEventArgs e)
{
if (e.Source.GetType() != typeof(TouchEvent.MainWindow))
{
}
}
}
}