public static void RemoveHandles(this UIElement element) { if (element == null || element.GetType() == typeof(ResizeHandle)) { return; } Guid elementId = element.GetElementId(); SectionCanvas canvas = element.FindParentControlBase(typeof(SectionCanvas)) as SectionCanvas; foreach (ResizeHandlesEnum item in Enum.GetValues(typeof(ResizeHandlesEnum))) { KeyValuePair <Guid, ResizeHandlesEnum> key = new KeyValuePair <Guid, ResizeHandlesEnum>(elementId, item); if (!elementHandles.ContainsKey(key)) { continue; } canvas.Children.Remove(elementHandles[key]); elementHandles.Remove(key); } }
public static void MoveObjects(double canvasWidth, double canvasHeight, double elementLeft, double elementWidth, double elementTop, double elementHeigth, double offsetLeft, double offsetTop ) { ResizeHandles.MoveObject(canvasWidth, canvasHeight, elementLeft, elementWidth, elementTop, elementHeigth); ResizeHandles.SelectedElement.MoveHandles(); Guid elementId = SelectedElement.GetElementId(); foreach (UIElement item in canvaselements.Values) { if (elementId == item.GetElementId()) { continue; } SectionCanvas itemCanvas = item.FindParentControlBase(typeof(SectionCanvas)) as SectionCanvas; double canvasItemWidth = ResizeHandles.SelectedElement.GetPropertyValue("ActualWidth").ToDouble(); double canvasItemHeigth = ResizeHandles.SelectedElement.GetPropertyValue("ActualHeight").ToDouble(); double canvasItemLeft = Canvas.GetLeft(item) + offsetLeft; double canvasItemTop = Canvas.GetTop(item) + offsetTop; if (canvasItemLeft <= 0 || canvasItemTop <= 0 || (canvasItemLeft + canvasItemWidth) > itemCanvas.ActualWidth || (canvasItemTop + canvasItemHeigth) > itemCanvas.ActualHeight) { continue; } Canvas.SetLeft(item, canvasItemLeft); Canvas.SetTop(item, canvasItemTop); item.MoveHandles(); } }
public static void NotchDown(double distance) { foreach (UIElement item in canvaselements.Values) { double notchPlacement = Canvas.GetTop(item) + distance; SectionCanvas parent = item.FindParentControlBase(typeof(SectionCanvas)) as SectionCanvas; double itemHeight = item.GetPropertyValue("ActualHeight").ToDouble(); if ((notchPlacement + itemHeight) > parent.ActualHeight) { notchPlacement = parent.ActualHeight - itemHeight; } Canvas.SetTop(item, notchPlacement); item.MoveHandles(); } }
public static void ShowHandles(this UIElement element, SectionCanvas canvas) { if (element.GetType() == typeof(ResizeHandle)) { return; } Guid elementId = element.GetElementId(); if (HaveHandles(elementId)) { return; } canvaselements.Add(elementId, element); CreateHandles(elementId); SetBounds(element); foreach (KeyValuePair <KeyValuePair <Guid, ResizeHandlesEnum>, ResizeHandle> hanle in elementHandles .Where(k => k.Key.Key == elementId && k.Key.Value != ResizeHandlesEnum.None)) { switch (hanle.Key.Value) { case ResizeHandlesEnum.LeftBottom: Canvas.SetTop(hanle.Value, bottom); Canvas.SetLeft(hanle.Value, left); break; case ResizeHandlesEnum.LetfTop: Canvas.SetTop(hanle.Value, top); Canvas.SetLeft(hanle.Value, left); break; case ResizeHandlesEnum.RightBottom: Canvas.SetTop(hanle.Value, bottom); Canvas.SetLeft(hanle.Value, right); break; case ResizeHandlesEnum.RightTop: Canvas.SetTop(hanle.Value, top); Canvas.SetLeft(hanle.Value, right); break; } canvas.Children.Add(hanle.Value); } }