Ejemplo n.º 1
0
        protected override void OnAttached()
        {
            this.attachedElement = base.AssociatedObject;
            if (this.attachedElement is ListBox)
            {
                return;
            }
            Panel panel = this.attachedElement as Panel;

            if (panel != null)
            {
                panel.Loaded += new RoutedEventHandler((object sender, RoutedEventArgs e) => panel.Children.Cast <UIElement>().ToList <UIElement>().ForEach((UIElement element) => Interaction.GetBehaviors(element).Add(new TiltBehavior()
                {
                    KeepDragging = this.KeepDragging,
                    TiltFactor   = this.TiltFactor
                })));
                return;
            }
            this.originalPanel  = this.attachedElement.Parent as Panel ?? TiltBehavior.GetParentPanel(this.attachedElement);
            this.originalMargin = this.attachedElement.Margin;
            this.originalSize   = new Size(this.attachedElement.Width, this.attachedElement.Height);
            double              left                = Canvas.GetLeft(this.attachedElement);
            double              right               = Canvas.GetRight(this.attachedElement);
            double              top                 = Canvas.GetTop(this.attachedElement);
            double              bottom              = Canvas.GetBottom(this.attachedElement);
            int                 zIndex              = Panel.GetZIndex(this.attachedElement);
            VerticalAlignment   verticalAlignment   = this.attachedElement.VerticalAlignment;
            HorizontalAlignment horizontalAlignment = this.attachedElement.HorizontalAlignment;

            this.RotatorParent = new Planerator()
            {
                Margin              = this.originalMargin,
                Width               = this.originalSize.Width,
                Height              = this.originalSize.Height,
                VerticalAlignment   = verticalAlignment,
                HorizontalAlignment = horizontalAlignment
            };
            this.RotatorParent.SetValue(Canvas.LeftProperty, left);
            this.RotatorParent.SetValue(Canvas.RightProperty, right);
            this.RotatorParent.SetValue(Canvas.TopProperty, top);
            this.RotatorParent.SetValue(Canvas.BottomProperty, bottom);
            this.RotatorParent.SetValue(Panel.ZIndexProperty, zIndex);
            this.originalPanel.Children.Remove(this.attachedElement);
            this.attachedElement.Margin = new Thickness();
            this.attachedElement.Width  = double.NaN;
            this.attachedElement.Height = double.NaN;
            this.originalPanel.Children.Add(this.RotatorParent);
            this.RotatorParent.Child     = this.attachedElement;
            CompositionTarget.Rendering += new EventHandler(this.CompositionTargetRendering);
        }
Ejemplo n.º 2
0
        private static Panel GetParentPanel(DependencyObject element)
        {
            DependencyObject parent = VisualTreeHelper.GetParent(element);
            object           obj    = parent as Panel;

            if (obj == null)
            {
                if (parent != null)
                {
                    return(TiltBehavior.GetParentPanel(parent));
                }
                obj = null;
            }
            return(obj);
        }