private Size GetAnchorOffset(LocationAnchor anchor, LayoutElement layoutItem) { switch (anchor) { case LocationAnchor.Top: return(new Size(layoutItem.Size.Width / 2, 0)); case LocationAnchor.Bottom: return(new Size(layoutItem.Size.Width / 2, layoutItem.Size.Height)); case LocationAnchor.Left: return(new Size(0, layoutItem.Size.Height / 2)); case LocationAnchor.Right: return(new Size(layoutItem.Size.Width, layoutItem.Size.Height / 2)); case LocationAnchor.Center: return(new Size(layoutItem.Size.Width / 2, layoutItem.Size.Height / 2)); case LocationAnchor.TopLeft: return(new Size(0, 0)); case LocationAnchor.TopRight: return(new Size(layoutItem.Size.Width, 0)); case LocationAnchor.BottomLeft: return(new Size(0, layoutItem.Size.Height)); case LocationAnchor.BottomRight: return(new Size(layoutItem.Size.Width, layoutItem.Size.Height)); default: throw new NotSupportedException($"{nameof(LocationAnchor)} {anchor} is not supported."); } }
/// <summary> Sets the anchor of a certain shape element. </summary> /// <param name="element"> Shape element for which a anchor should be set. </param> /// <param name="anchor"> New anchor of the shape element. </param> public static void SetAnchor(FrameworkElement element, LocationAnchor anchor) { element.SetValue(AnchorProperty, anchor); }