/// <summary> /// タッチダウンイベント時に呼び出して、キャプチャやe.Handledを制御する為のメソッド /// </summary> public void button_TouchDown(object sender, TouchEventArgs e) { FrameworkElement button = sender as FrameworkElement; if (button == null) { return; } button.CaptureTouch(e.TouchDevice); e.Handled = true; }
/// <summary> /// Drag in canvas /// </summary> /// <param name="dragTarget">drag target</param> /// <param name="dragElement">drag element</param> /// <param name="bound">bound</param> /// <returns></returns> public static bool BindDrag(this FrameworkElement dragTarget, FrameworkElement dragElement, DragBound bound, Action <Point, bool> positonChangeCallback = null) { bool result = false; if (dragTarget.Parent != null && (dragTarget.Parent as Canvas) != null) { Canvas moveCvs = dragTarget.Parent as Canvas; Point positionOnElement = new Point(); bool isDrag = false; int deviceId = 0; DragBoundCheck check = new DragBoundCheck(dragTarget, bound); dragElement.PreviewTouchDown += delegate(object sender, TouchEventArgs e) { IDrag dragObj = dragTarget as IDrag; if (dragObj != null && dragObj.IsDrag == false) { return; } if (isDrag == false) { deviceId = e.TouchDevice.Id; positionOnElement = e.GetTouchPoint(dragTarget).Position; isDrag = true; dragElement.CaptureTouch(e.TouchDevice); } }; dragElement.PreviewTouchMove += delegate(object sender, TouchEventArgs e) { if (isDrag && e.TouchDevice.Id == deviceId) { SetNewMovPosition(dragTarget, positonChangeCallback, moveCvs, positionOnElement, false, e); } }; dragElement.PreviewTouchUp += delegate(object sender, TouchEventArgs e) { if (isDrag && deviceId == e.TouchDevice.Id) { isDrag = false; SetNewMovPosition(dragTarget, positonChangeCallback, moveCvs, positionOnElement, true, e); dragElement.ReleaseTouchCapture(e.TouchDevice); } }; result = true; } return(result); }