Esempio n. 1
0
        /// <summary>
        /// Prepares a control to be tilted by setting up a plane projection and
        /// some event handlers.
        /// </summary>
        /// <param name="element">The control that is to be tilted.</param>
        /// <param name="centerDelta">Delta between the element's center and the
        /// tilt container's.</param>
        /// <returns>true if successful; false otherwise.</returns>
        /// <remarks>
        /// This method is conservative; it will fail any attempt to tilt a 
        /// control that already has a projection on it.
        /// </remarks>
        private static bool PrepareControlForTilt(FrameworkElement element, Point centerDelta, Pointer p)
        {
            // Prevents interference with any existing transforms
            if (element.Projection != null || (element.RenderTransform != null && element.RenderTransform.GetType() != typeof(MatrixTransform)))
            {
                return false;
            }

            _originalCacheMode[element] = element.CacheMode;
            element.CacheMode = new BitmapCache();

            TranslateTransform transform = new TranslateTransform();
            transform.X = centerDelta.X;
            transform.Y = centerDelta.Y;
            element.RenderTransform = transform;

            PlaneProjection projection = new PlaneProjection();
            projection.GlobalOffsetX = -1 * centerDelta.X;
            projection.GlobalOffsetY = -1 * centerDelta.Y;
            element.Projection = projection;

            element.PointerMoved += TiltEffect_PointerMoved;
            element.PointerReleased += TiltEffect_PointerReleased;
            element.CapturePointer(p);
            return true;
        }
Esempio n. 2
0
        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;
        }