I am working on a touch screen application. This app is for a certain area, but the general ideals are all that is needed to explain the problem. To begin, I do an intensive course on WPF and allow a user to add a new command (Shape – Rectangle), then assign functions. For example, they can add one, then add a second, then a third, and so on, placing them where they want.
What I would like to know, is how to tell the API when inertia occurs and say that a user touches a shape and then throws it across the screen, for that the event does not end only when it reaches the edge of the screen (does it already), but also if it cuts or hits another shape. The following is the general code for quick basic validation.
void Window_ManipulationDelta (object sender, ManipulationDeltaEventArgs e)
// Get the rectangle and its RenderTransform matrix.
Rectangle rectToMove = e.OriginalSource as Rectangle;
Matrix rectsMatrix = ((MatrixTransform) rectToMove.RenderTransform) .Matrix;
// Rotate the rectangle.
// Resize the rectangle. Keep the square
// therefore uses only the X value of Scale.
// move the rectangle.
// Apply the changes to the rectangle.
rectToMove.RenderTransform = new MatrixTransform (rectsMatrix);
Rect containingRect =
new Rect (((FrameworkElement) e.ManipulationContainer) .RenderSize);
Rect shapeBounds =
new Rect (rectToMove.RenderSize));
// Check if the rectangle is completely in the window.
// If this is not the case and the intertia is running, stop the manipulation.
if (e.IsInertial &&! containingRect.Contains (shapeBounds))
// convert the current move rect to the new rect drawing type
var tempRect = new Rect (Canvas.GetLeft (rectToMove), Canvas.GetTop (rectToMove), rectToMove.Width, rectToMove.Height);
// we must first convert SytsemWindows.Shapes.Rectablge to SystemWindows.Drawing.Rect
//Listing removeCurrent = Commands.Where (r => r! = rectToMove) .ToList ();
//Listing Coordinates = Commands.Where (r => r.Name! = RectToMove.Name) .Select (r => new Rect (Canvas.GetLeft (r), Canvas.GetTop (r), r.Width, r.Height)) .Lister ();
listing recs = new list();
listing test = Commands.Where (r => r.Name! = rectToMove.Name) .ToList ();
foreach (System.Windows.Shapes.Rectangle re in the test)
if (re! = rectToMove)
recs.Add (new Rect (Canvas.GetLeft (re), Canvas.GetTop (re), re.Width, re.Height));
// if the rect element is moving inertia and it crosses an already established command order, then stop.
if (recs.Any (c => c.InteriorIntersectsWith (tempRect)))
// There is an overlap
catch (Exception ex)
e.Handled = true;
The problem is that the inertia works well. Once a second shape is then added to the canvas, the inertia no longer works. The user can click and drag them, but while trying to flick through the shapes, they stop instantly, as if she was signaling from all positions that she was intersecting with another form even if they were not close to each other. Any ideas on what I'm doing wrong?