protected override void OnInitialized() { base.OnInitialized(); if (this.ExtendedItem.Parent != null) { if (this.ExtendedItem.Parent.ComponentType == typeof(Canvas)) { FrameworkElement extendedControl = (FrameworkElement)this.ExtendedItem.Component; AdornerPanel adornerPanel = new AdornerPanel(); // If the Element is rotated/skewed in the grid, then margin handles do not appear if (extendedControl.LayoutTransform.Value == Matrix.Identity && extendedControl.RenderTransform.Value == Matrix.Identity) { _canvas = this.ExtendedItem.Parent.View as Canvas; _handles = new[] { _leftHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Left), _topHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Top), _rightHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Right), _bottomHandle = new CanvasPositionHandle(ExtendedItem, adornerPanel, HandleOrientation.Bottom), }; } if (adornerPanel != null) this.Adorners.Add(adornerPanel); } } }
protected override void OnInitialized() { base.OnInitialized(); if (this.ExtendedItem.Parent != null) { if (this.ExtendedItem.Parent.ComponentType == typeof(Grid)){ FrameworkElement extendedControl = (FrameworkElement)this.ExtendedItem.Component; AdornerPanel adornerPanel = new AdornerPanel(); // If the Element is rotated/skewed in the grid, then margin handles do not appear if (extendedControl.LayoutTransform.Value == Matrix.Identity && extendedControl.RenderTransform.Value == Matrix.Identity) { _grid = this.ExtendedItem.Parent.View as Grid; _handles = new[] { _leftHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Left), _topHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Top), _rightHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Right), _bottomHandle = new MarginHandle(ExtendedItem, adornerPanel, HandleOrientation.Bottom), }; foreach(var handle in _handles) { handle.MouseLeftButtonDown += OnMouseDown; handle.Stub.PreviewMouseLeftButtonDown += OnMouseDown; } } if (adornerPanel != null) this.Adorners.Add(adornerPanel); } } }
public void HandleLength() { Intialize(); var handle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Left); Assert.AreEqual(21, handle.HandleLength); Assert.IsTrue(handle.Visibility == Visibility.Visible, "Handle is not visible"); Assert.IsTrue(handle.Stub.Visibility == Visibility.Hidden, "Stub is Visible"); }
public void ChangeHorizontalAlignment() { var leftHandle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Left); var rightHandle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Right); _button.Properties[FrameworkElement.HorizontalAlignmentProperty].SetValue(HorizontalAlignment.Right); Assert.IsFalse(leftHandle.Visibility == Visibility.Visible, "Left Handle is visible"); Assert.IsFalse(leftHandle.Stub.Visibility == Visibility.Hidden, "Left Stub is not Visible"); Assert.IsTrue(rightHandle.Visibility == Visibility.Visible, "Right Handle is not visible"); Assert.IsTrue(rightHandle.Stub.Visibility == Visibility.Hidden, "Right Stub is Visible"); }
public void ResizeTest(double width,double height) { var handle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Left); var grid = _button.Parent.View; grid.Measure(grid.DesiredSize); grid.Arrange(new Rect(grid.DesiredSize)); grid.UpdateLayout(); PlacementTests.Resize(new Rect(20, 20, width, height), _button); Assert.AreEqual(20, handle.HandleLength); Assert.IsTrue(handle.Visibility == Visibility.Visible, "Handle is not visible"); Assert.IsTrue(handle.Stub.Visibility == Visibility.Hidden, "Stub is Visible"); }
public void MoveTest() { Intialize(); var handle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Left); var grid = _button.Parent.View; grid.Measure(grid.DesiredSize); grid.Arrange(new Rect(grid.DesiredSize)); grid.UpdateLayout(); PlacementTests.Move(new Vector(20, 20), _button); Assert.AreEqual(41,handle.HandleLength); Assert.IsTrue(handle.Visibility == Visibility.Visible, "Handle is not visible"); Assert.IsTrue(handle.Stub.Visibility == Visibility.Hidden, "Stub is Visible"); }
public MarginStub(MarginHandle marginHandle) { this.marginHandle = marginHandle; }
public void ChangeVerticalAlignment() { var topHandle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Top); var bottomHandle = new MarginHandle(_button, new AdornerPanel(), HandleOrientation.Bottom); _button.Properties[FrameworkElement.VerticalAlignmentProperty].SetValue(VerticalAlignment.Bottom); Assert.IsFalse(topHandle.Visibility == Visibility.Visible, "Top Handle is visible"); Assert.IsFalse(topHandle.Stub.Visibility == Visibility.Hidden, "Top Stub is not Visible"); Assert.IsTrue(bottomHandle.Visibility == Visibility.Visible, "Bottom Handle is not visible"); Assert.IsTrue(bottomHandle.Stub.Visibility == Visibility.Hidden, "Bottom Stub is Visible"); }