private UIElement GetManipulatableElement() { UIElement element = InputElement.GetContainingUIElement(_directlyOver as DependencyObject) as UIElement; if (element != null) { element = Manipulation.FindManipulationParent(element); } return(element); }
private void PromoteMainToManipulation(UIElement manipulatableElement, TouchEventArgs touchEventArgs) { RoutedEvent routedEvent = touchEventArgs.RoutedEvent; if (routedEvent == Touch.TouchDownEvent) { // When touch goes down or if we're in the middle of a move, capture so that we can // start manipulation. We could be in the middle of a move if a device delayed // promotion, such as the StylusTouchDevice, due to other gesture detection. Capture(manipulatableElement); } else if ((routedEvent == Touch.TouchUpEvent) && PromotingToManipulation) { // When touch goes up, release capture so that we can stop manipulation. Capture(null); } else if ((routedEvent == Touch.GotTouchCaptureEvent) && !PromotingToManipulation) { UIElement element = _captured as UIElement; if (element != null && element.IsManipulationEnabled) { // When touch gets capture and if the captured element // is manipulable, then add it as a manipulator to // the captured element. _manipulatingElement = new WeakReference(element); Manipulation.AddManipulator(element, this); PromotingToManipulation = true; OnManipulationStarted(); } } else if ((routedEvent == Touch.LostTouchCaptureEvent) && PromotingToManipulation && _manipulatingElement != null) { UIElement element = _manipulatingElement.Target as UIElement; _manipulatingElement = null; if (element != null) { // When touch loses capture, remove it as a manipulator. Manipulation.TryRemoveManipulator(element, this); PromotingToManipulation = false; } } }