private void OnPointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs args) { if (args.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Pen) { return; } _target.Opacity = this.SelectionOpacity; var indexes = new List <int>(); Panel panel = _target.FindVisualParent <Panel>(); if (panel != null) { foreach (UIElement element in panel.Children) { if (element != _target as UIElement) { indexes.Add(Canvas.GetZIndex(element)); } } Int16 currentIndex = 0; if (indexes.Count > 0 && indexes.Max() < Int16.MaxValue) { currentIndex = (Int16)indexes.Max(); ContentPresenter presenter = _target as ContentPresenter; if (presenter != null) { presenter.SetValue(Canvas.ZIndexProperty, indexes.Max() + 1); } } else if (indexes.Count > 0 && indexes.Max() >= Int16.MaxValue) { // Need to rearrange all ZIndexs! var result = panel.Children.OrderBy(x => Canvas.GetZIndex(x)); Int16 count = 0; foreach (UIElement element in result) { if (element != _target as UIElement) { element.SetValue(Canvas.ZIndexProperty, count); } count++; } //at the end we set the ZIndex of our element as the highest ContentPresenter presenter = _target as ContentPresenter; if (presenter != null) { presenter.SetValue(Canvas.ZIndexProperty, count); } } } // Obtain current point in the coordinate system of the reference element Windows.UI.Input.PointerPoint currentPoint = args.GetCurrentPoint(_reference); // Route the event to the gesture recognizer _gestureRecognizer.ProcessDownEvent(currentPoint); // Capture the pointer associated to this event _target.CapturePointer(args.Pointer); // Mark event handled, to prevent execution of default event handlers args.Handled = true; }