void Touch_FrameReported(object sender, TouchFrameEventArgs e) { TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null); // Inhibit mouse promotion if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down) e.SuspendMousePromotionUntilTouchUp(); TouchPointCollection touchPoints = e.GetTouchPoints(null); foreach (var item in touchPoints) { if (item.Action == TouchAction.Down) { //if (item.TouchDevice.DirectlyOver == image1) //{ a = true; //} Image touchIsImage = item.TouchDevice.DirectlyOver as Image; if (touchIsImage != null && touchIsImage.Name != "originalImage") { try { Carrier.Children.Remove(item.TouchDevice.DirectlyOver);//移掉Image控件在Carrier的子节点 g.Children.Remove(item.TouchDevice.DirectlyOver);//移掉Image控件在Grid的子节点 Carrier.Children.Add(item.TouchDevice.DirectlyOver);//移掉Image控件在Carrier的子节点 } catch { } finally { } //try //{ // Carrier.Children.Add(item.TouchDevice.DirectlyOver);//移掉Image控件在Carrier的子节点 //} //catch { } downDirectlyOver = item.TouchDevice.DirectlyOver.GetValue(NameProperty).ToString(); } originalImage.Visibility = Visibility.Collapsed; } if (item.Action == TouchAction.Move) { moveDirectlyOver = item.TouchDevice.DirectlyOver.GetValue(NameProperty).ToString(); if (a == true && moveDirectlyOver == downDirectlyOver) { Canvas.SetLeft(item.TouchDevice.DirectlyOver, item.Position.X - smallSquareWidth / 1.8); Canvas.SetTop(item.TouchDevice.DirectlyOver, item.Position.Y - smallSquareHeight / 1.8); Canvas.SetZIndex(item.TouchDevice.DirectlyOver, 999);//处于最上端 } } if (item.Action == TouchAction.Up) { a = false; if (gameClass == "5And5") { #region 第一行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[0, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[1, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 0, 0); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 1, 1); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 2, 2); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 3, 3); } //5 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 5].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 4, 4); } } #endregion #region 第二行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[1, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[2, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 0, 5); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 1, 6); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 2, 7); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 3, 8); } //5 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 5].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 4, 9); } } #endregion #region 第三行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[2, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[3, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 0, 10); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 1, 11); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 2, 12); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 3, 13); } //5 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 5].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 4, 14); } } #endregion #region 第四行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[3, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[4, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 0, 15); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 1, 16); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 2, 17); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 3, 18); } //5 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 5].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 4, 19); } } #endregion #region 第五行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[4, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[5, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 0, 20); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 1, 21); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 2, 22); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[5, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 3, 23); } //5 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[4, 4].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[4, 5].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 4, 4, 24); } } #endregion } if (gameClass == "4And4") { #region 第一行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[0, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[1, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 0, 0); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 1, 1); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 2, 2); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 3, 3); } } #endregion #region 第二行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[1, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[2, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 0, 4); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 1, 5); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 2, 6); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 3, 7); } } #endregion #region 第三行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[2, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[3, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 0, 8); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 1, 9); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 2, 10); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 3, 11); } } #endregion #region 第四行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[3, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[4, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 0, 12); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 1, 13); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 2, 14); } //4 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[3, 3].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[3, 4].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 3, 3, 15); } } #endregion } if (gameClass == "3And3") { #region 第一行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[0, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[1, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 0, 0); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 1, 1); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[0, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[0, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 0, 2, 2); } } #endregion #region 第二行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[1, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[2, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 0, 3); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 1, 4); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[1, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[1, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 1, 2, 5); } } #endregion #region 第三行 if (Canvas.GetTop(item.TouchDevice.DirectlyOver) > (380 + tableVectors[2, 0].y) && Canvas.GetTop(item.TouchDevice.DirectlyOver) <= (380 + tableVectors[3, 0].y)) { //1 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 0].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 1].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 0, 6); } //2 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 1].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 2].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 1, 7); } //3 if (Canvas.GetLeft(item.TouchDevice.DirectlyOver) >= tableVectors[2, 2].x && Canvas.GetLeft(item.TouchDevice.DirectlyOver) <= tableVectors[2, 3].x) { MagnetFunc((FrameworkElement)item.TouchDevice.DirectlyOver, 2, 2, 8); } } #endregion } Canvas.SetZIndex(item.TouchDevice.DirectlyOver, 0);//使拼图返回到原来的层次 } } }
void Touch_FrameReported(object sender, TouchFrameEventArgs e) { TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null); // Inhibit mouse promotion if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down) e.SuspendMousePromotionUntilTouchUp(); TouchPointCollection touchPoints = e.GetTouchPoints(null); foreach (var item in touchPoints) { Rectangle touchIsRectangle = item.TouchDevice.DirectlyOver as Rectangle; while (TouchPanel.IsGestureAvailable) { GestureSample gs = TouchPanel.ReadGesture(); switch (gs.GestureType) { case GestureType.Pinch: // Vector2 a = gs.Position; //取得第一個觸碰點 //Vector2 aOld = gs.Position - gs.Delta;//取得第一個觸碰點的起始位置 //Vector2 b = gs.Position2; //取得第二個觸碰點 //Vector2 bOld = gs.Position2 - gs.Delta2;//取得第二個觸碰點的起始位置 //float d = Vector2.Distance(a, b); //計算兩個觸碰點之間的距離 //float dOld = Vector2.Distance(aOld, bOld);//計算兩個原始座標之間的距離 //float scaleChange = (d - dOld) * .01f; //計算距離的變化量 //Scale += scaleChange; //將距離變化量的 1/10 當做縮放的比例 if (touchIsRectangle != null) { double d1 = Math.Sqrt(Math.Abs(gs.Position.X - gs.Position2.X) * Math.Abs(gs.Position.X - gs.Position2.X) + Math.Abs(gs.Position.Y - gs.Position2.Y) * Math.Abs(gs.Position.Y - gs.Position2.Y)); double d2 = Math.Sqrt(Math.Abs((gs.Position.X - gs.Delta.X) - (gs.Position2.X - gs.Delta2.X)) * Math.Abs((gs.Position.X - gs.Delta.X) - (gs.Position2.X - gs.Delta2.X)) + Math.Abs((gs.Position.Y - gs.Delta.Y) - (gs.Position2.Y - gs.Delta2.Y)) * Math.Abs((gs.Position.Y - gs.Delta.Y) - (gs.Position2.Y - gs.Delta2.Y))); double distance = (d1 - d2) * 0.5; _cutImgRect.Width += distance; _cutImgRect.Height += distance; } break; } } if (item.Action == TouchAction.Down) { if (touchIsRectangle != null) { lastRectPositionX = item.Position.X - Canvas.GetLeft(_cutImgRect); lastRectPositionY = item.Position.Y - Canvas.GetTop(_cutImgRect); } } if (item.Action == TouchAction.Move) { if (touchIsRectangle != null) { Canvas.SetLeft(item.TouchDevice.DirectlyOver, item.Position.X - lastRectPositionX); Canvas.SetTop(item.TouchDevice.DirectlyOver, item.Position.Y - lastRectPositionY); Canvas.SetZIndex(item.TouchDevice.DirectlyOver, 999);//处于最上端 } } } }
// Win 7 / Silverlight 3 standard WM_TOUCH messages MultiTouch device input void Touch_FrameReported(object sender, TouchFrameEventArgs e) { TouchPointCollection touchcollection = e.GetTouchPoints(_targetelement); TouchPoint primarytouch = e.GetPrimaryTouchPoint(_targetelement); if (_tpids.Count == 0 && primarytouch != null && primarytouch.Action == TouchAction.Down) { try { IEnumerable<UIElement> hits = VisualTreeHelper.FindElementsInHostCoordinates(_targetelement.TransformToVisual(Application.Current.RootVisual).Transform(primarytouch.Position), Application.Current.RootVisual); foreach (UIElement uiel in hits) { if (typeof(Touchable).IsAssignableFrom(uiel.GetType()) || _hastouchableparent(uiel)) { e.SuspendMousePromotionUntilTouchUp(); break; } else if (typeof(Control).IsAssignableFrom(uiel.GetType())) { return; } } } catch (Exception ex) { } } lock (this) { List<int> removed = new List<int>(); for (int i = 0; i < touchcollection.Count; i++) { if (i + 1 > _tpids.Count) { int max = 1; for (int c = 0; c < _tpids.Count; c++) max = Math.Max(max, int.Parse(_tpids[c]) + 1000); _tpids.Add((max).ToString()); _cursoradd("WM_TOUCH:" + (max).ToString()); } TouchPoint tp = touchcollection[i]; if (tp.Action == TouchAction.Up) { _cursordel("WM_TOUCH:" + _tpids[i]); removed.Add(i); } else { _cursorupd("WM_TOUCH:" + _tpids[i], touchcollection[i].Position); } } removed.Reverse(); foreach (int r in removed) _tpids.RemoveAt(r); } }
void Touch_FrameReported(object sender, TouchFrameEventArgs e) { TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null); // Inhibit mouse promotion if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down) e.SuspendMousePromotionUntilTouchUp(); TouchPointCollection touchPoints = e.GetTouchPoints(null); foreach (var item in touchPoints) { while (TouchPanel.IsGestureAvailable) { Image touchIsImage = item.TouchDevice.DirectlyOver as Image; GestureSample gs = TouchPanel.ReadGesture(); switch (gs.GestureType) { case GestureType.Tap: InfoControl.Visibility = Visibility.Collapsed;//隐藏用户控件CancelControl if (lastTouchImage != null) { lastTouchImage.Width = 200; lastTouchImage.Height = 200; } if (touchIsImage != null) { //触摸图片变小 touchIsImage.Width = 190; touchIsImage.Height = 190; NavigationService.Navigate(new Uri("/MainPage.xaml?gameClass=" + gameClass + "&imgUri=" + touchIsImage.Name, UriKind.Relative)); Touch.FrameReported -= Touch_FrameReported; } break; case GestureType.DoubleTap: break; case GestureType.Hold: if (touchIsImage != null) { //触摸图片变小 lastTouchImage = touchIsImage; touchIsImage.Width = 150; touchIsImage.Height = 150; deleteImg = touchIsImage.Name; InfoControl.Visibility = Visibility.Visible; InfoControl.Margin = new Thickness(0, item.Position.Y, 0, 0); } break; case GestureType.FreeDrag: break; case GestureType.HorizontalDrag: break; case GestureType.VerticalDrag: break; case GestureType.Flick: break; } } } }
void Touch_FrameReported(object sender, TouchFrameEventArgs e) { TouchPoint primaryTouchPoint = e.GetPrimaryTouchPoint(null); if (primaryTouchPoint != null && primaryTouchPoint.Action == TouchAction.Down) { e.SuspendMousePromotionUntilTouchUp(); } TouchPoint touchPoint = (e.GetTouchPoints(inkPresenter))[0]; Point pt = touchPoint.Position; int id = touchPoint.TouchDevice.Id; switch (touchPoint.Action) { case TouchAction.Down: Stroke stroke = new Stroke(); stroke.DrawingAttributes.Color = Colors.DarkGray; stroke.DrawingAttributes.Height = 4; stroke.DrawingAttributes.Width = 4; stroke.StylusPoints.Add(new StylusPoint(pt.X, pt.Y)); inkPresenter.Strokes.Add(stroke); activeStokes.Add(id, stroke); break; case TouchAction.Move: activeStokes[id].StylusPoints.Add(new StylusPoint(pt.X, pt.Y)); break; case TouchAction.Up: activeStokes[id].StylusPoints.Add(new StylusPoint(pt.X, pt.Y)); activeStokes.Remove(id); DoneNumber += 1; break; } }