protected override void OnAttached() { attachedElement = AssociatedObject; if (attachedElement is ListBox) { var l = (ListBox)attachedElement; l.Items.CurrentChanging += (s, e) => { Console.WriteLine("foo"); }; return; } if (attachedElement as Panel != null) { var y = (attachedElement as ItemsControl); y.Items.CurrentChanging += (s, e) => { Console.WriteLine("foo"); }; (attachedElement as Panel).Loaded += (sl, el) => { List <UIElement> elements = new List <UIElement>(); foreach ( UIElement ui in (attachedElement as Panel).Children) { elements.Add(ui); } elements.ForEach( (element) => Interaction.GetBehaviors(element).Add( new TiltBehavior { KeepDragging = KeepDragging, TiltFactor = TiltFactor })); }; return; } OriginalPanel = attachedElement.Parent as Panel ?? GetParentPanel(attachedElement); OriginalMargin = attachedElement.Margin; OriginalSize = new Size(attachedElement.Width, attachedElement.Height); double left = Canvas.GetLeft(attachedElement); double right = Canvas.GetRight(attachedElement); double top = Canvas.GetTop(attachedElement); double bottom = Canvas.GetBottom(attachedElement); int z = Panel.GetZIndex(attachedElement); VerticalAlignment va = attachedElement.VerticalAlignment; HorizontalAlignment ha = attachedElement.HorizontalAlignment; RotatorParent = new Planerator { Margin = OriginalMargin, Width = OriginalSize.Width, Height = OriginalSize.Height, VerticalAlignment = va, HorizontalAlignment = ha }; RotatorParent.SetValue(Canvas.LeftProperty, left); RotatorParent.SetValue(Canvas.RightProperty, right); RotatorParent.SetValue(Canvas.TopProperty, top); RotatorParent.SetValue(Canvas.BottomProperty, bottom); RotatorParent.SetValue(Panel.ZIndexProperty, z); OriginalPanel.Children.Remove(attachedElement); attachedElement.Margin = new Thickness(); attachedElement.Width = double.NaN; attachedElement.Height = double.NaN; OriginalPanel.Children.Add(RotatorParent); RotatorParent.Child = attachedElement; CompositionTarget.Rendering += CompositionTargetRendering; }
protected override void OnAttached() { attachedElement = AssociatedObject; if (attachedElement is ListBox) { return; } var attachedElementPanel = attachedElement as Panel; if (attachedElementPanel != null) { attachedElementPanel.Loaded += (sl, el) => { var elements = attachedElementPanel.Children.Cast <UIElement>().ToList(); elements.ForEach(element => Interaction.GetBehaviors(element).Add( new TiltBehavior { KeepDragging = KeepDragging, TiltFactor = TiltFactor })); }; return; } originalPanel = attachedElement.Parent as Panel ?? GetParentPanel(attachedElement); originalMargin = attachedElement.Margin; originalSize = new Size(attachedElement.Width, attachedElement.Height); double left = Canvas.GetLeft(attachedElement); double right = Canvas.GetRight(attachedElement); double top = Canvas.GetTop(attachedElement); double bottom = Canvas.GetBottom(attachedElement); int z = Panel.GetZIndex(attachedElement); VerticalAlignment va = attachedElement.VerticalAlignment; HorizontalAlignment ha = attachedElement.HorizontalAlignment; RotatorParent = new Planerator { Margin = originalMargin, Width = originalSize.Width, Height = originalSize.Height, VerticalAlignment = va, HorizontalAlignment = ha }; RotatorParent.SetValue(Canvas.LeftProperty, left); RotatorParent.SetValue(Canvas.RightProperty, right); RotatorParent.SetValue(Canvas.TopProperty, top); RotatorParent.SetValue(Canvas.BottomProperty, bottom); RotatorParent.SetValue(Panel.ZIndexProperty, z); originalPanel.Children.Remove(attachedElement); attachedElement.Margin = new Thickness(); attachedElement.Width = double.NaN; attachedElement.Height = double.NaN; originalPanel.Children.Add(RotatorParent); RotatorParent.Child = attachedElement; CompositionTarget.Rendering += CompositionTargetRendering; }