protected DesignerThumb CreateThumb(PlacementAlignment alignment, Cursor cursor) { DesignerThumb designerThumb = new DesignerThumb { Alignment = alignment, Cursor = cursor, IsPrimarySelection = true}; AdornerPanel.SetPlacement(designerThumb, Place(designerThumb, alignment)); adornerPanel.Children.Add(designerThumb); DragListener = new DragListener(designerThumb); DragListener.Started += drag_Started; DragListener.Changed += drag_Changed; DragListener.Completed += drag_Completed; return designerThumb; }
/// <summary> /// Places resize thumbs at their respective positions /// and streches out thumbs which are at the center of outline to extend resizability across the whole outline /// </summary> /// <param name="designerThumb"></param> /// <param name="alignment"></param> /// <param name="index">if using a polygon or multipoint adorner this is the index of the point in the Points array</param> /// <returns></returns> protected PointTrackerPlacementSupport Place(ref DesignerThumb designerThumb, PlacementAlignment alignment, int index = -1) { PointTrackerPlacementSupport placement = new PointTrackerPlacementSupport(ExtendedItem.View as Shape, alignment, index); return placement; }
/// <summary> /// Places resize thumbs at their respective positions /// and streches out thumbs which are at the center of outline to extend resizability across the whole outline /// </summary> /// <param name="designerThumb"></param> /// <param name="alignment"></param> /// <returns></returns> private RelativePlacement Place(ref DesignerThumb designerThumb,PlacementAlignment alignment) { RelativePlacement placement = new RelativePlacement(alignment.Horizontal,alignment.Vertical); if (alignment.Horizontal == HorizontalAlignment.Center) { placement.WidthRelativeToContentWidth = 1; placement.HeightOffset = 6; designerThumb.Opacity = 0; return placement; } if (alignment.Vertical == VerticalAlignment.Center) { placement.HeightRelativeToContentHeight = 1; placement.WidthOffset = 6; designerThumb.Opacity = 0; return placement; } placement.WidthOffset = 6; placement.HeightOffset = 6; return placement; }
/// <summary> /// is invoked whenever a line is selected on the canvas, remember that the adorners are created for each line object and never destroyed /// </summary> protected override void OnInitialized() { base.OnInitialized(); resizeThumbs = new DesignerThumb[] { CreateThumb(PlacementAlignment.TopLeft, Cursors.Cross), CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross) }; extendedItemArray[0] = this.ExtendedItem; Invalidate(); this.ExtendedItem.PropertyChanged += OnPropertyChanged; resizeBehavior = PlacementOperation.GetPlacementBehavior(extendedItemArray); UpdateAdornerVisibility(); }