public QGBindingLayer(IQGControl parentControl) { this.ChildControls = new QGControlCollection(this); this.ParentControl = parentControl; this.ParentControl.RegisterControlInitMethod(c => __initialize(this.ParentControl.WPFPrimaryElement)); }
private void __UpdateLayerBoundaries(IQGControl control) { this.RightmostControl ??= control; this.BottommostControl ??= control; double elXedge = control.GetRightEdge(); double elYedge = control.GetBottomEdge(); if (elXedge > _rightEdge) { this.RightmostControl = control; _rightEdge = elXedge; } else if (elXedge < _rightEdge && this.RightmostControl == control) { this.RightmostControl = __selectControl(this.ChildControls, (c1, c2) => c1.GetRightEdge() > c2.GetRightEdge() ? c1 : c2); _rightEdge = this.RightmostControl.GetRightEdge(); } if (elYedge > _bottomEdge) { this.BottommostControl = control; _bottomEdge = elYedge; } else if (elYedge < _bottomEdge && this.BottommostControl == control) { this.BottommostControl = __selectControl(this.ChildControls, (c1, c2) => c1.GetBottomEdge() > c2.GetBottomEdge() ? c1 : c2); _bottomEdge = this.BottommostControl.GetBottomEdge(); } if (this.Width != _rightEdge || this.Height != _bottomEdge) { this.SetSize(_rightEdge, _bottomEdge); } }
private void __registerParent(IQGControl sender) { if (this.ParentLayer == null && this.Vertex1.IsInitialized && this.Vertex2.IsInitialized) { IQGLayer.FindNearestCommonLayer(this.Vertex1, this.Vertex2).ChildControls.Add(this); } }
private void __initializeWPFElement(object caller, UIElement wpfElement) { IQGControl control = (IQGControl)caller; QGControlAdorner adorner = this.ControlAdorners[control]; adorner.AdornerVisualCollection.Add(wpfElement); }
private void __UpdateBoundariesAfterElementRemoval(IQGControl control) { if (this.RightmostControl == control) { this.RightmostControl = __selectControl(this.ChildControls, (c1, c2) => c1.GetRightEdge() > c2.GetRightEdge() ? c1 : c2); _rightEdge = this.RightmostControl?.GetRightEdge() ?? 0; } if (this.BottommostControl == control) { this.BottommostControl = __selectControl(this.ChildControls, (c1, c2) => c1.GetBottomEdge() > c2.GetBottomEdge() ? c1 : c2); _bottomEdge = this.BottommostControl?.GetBottomEdge() ?? 0; } }
void IQGLayer.OnRemovingControl(IQGControl control) { if (!this.ControlAdorners.ContainsKey(control)) { throw new Exception("Cannot remove control from binding layer: it is not present within the layer."); } control.SetParentLayer(null); QGControlAdorner adorner = this.ControlAdorners[control]; this.ControlAdorners.Remove(control); this.WPFAdornerLayer?.Remove(adorner); this.OnRemovingControl(control); }
private IQGControl __selectControl(IEnumerable <IQGControl> controls, Func <IQGControl, IQGControl, IQGControl> selector) { if (controls == null || !controls.Any()) { return(null); } IQGControl currentSelection = controls.First(); foreach (IQGControl item in controls) { currentSelection = selector(currentSelection, item); } return(currentSelection); }
void IQGLayer.OnAddingControl(IQGControl control) { control.SetParentLayer(this); QGControlAdorner adorner = new QGControlAdorner(this.ParentControl); this.ControlAdorners.Add(control, adorner); this.WPFAdornerLayer?.Add(adorner); if (control is IWPFContainer wpfContainer) { wpfContainer.RegisterWPFElementInitMethod(__initializeWPFElement); } this.UpdateControlPosition(control); this.OnAddingControl(control); }
public void UpdateControlPosition(IQGControl child) { if (!this.ChildControls.Contains(child)) { throw new Exception("Cannot update control position: control is not a child of the calling layer."); } Point wpfControlPoint = ((IQGLayer)this).GetRenderingCoordinatesOf(child.Position); foreach (WPFElementInfo elementInfo in child.WPFElementInfoEnumeration) { Point wpfRenderPoint = wpfControlPoint + child.GetAlignmentOffset(elementInfo.Size) + elementInfo.PositionOffset; Rect wpfDimensions = new Rect(wpfRenderPoint, elementInfo.Size); if (!Double.IsFinite(elementInfo.Size.Width) || !Double.IsFinite(elementInfo.Size.Height)) { break; } elementInfo.UIElement.Arrange(wpfDimensions); } }
public static double GetBottomEdge(this IQGControl control) { return(control.Y + (control.RenderSize.Height + control.GetAlignmentOffset().Y)); }
protected override void OnRemovingControl(IQGControl control) { control.PositionChange -= __updateControlOnMove; control.SizeChange -= __updateControlOnResize; __UpdateBoundariesAfterElementRemoval(control); }
protected override void OnAddingControl(IQGControl control) { __UpdateLayerBoundaries(control); control.PositionChange += __updateControlOnMove; control.SizeChange += __updateControlOnResize; }
public static double GetRightEdge(this IQGControl control) { return(control.X + (control.RenderSize.Width + control.GetAlignmentOffset().X)); }
protected virtual void OnRemovingControl(IQGControl control) { }
public QGControlAdorner(IQGControl parentControl) : base(parentControl.WPFPrimaryElement) { this.ParentControl = parentControl; this.AdornerVisualCollection = new VisualCollection(this); }
protected virtual void OnAddingControl(IQGControl control) { }
void IQGLayer.UpdateControlPosition(IQGControl child) => this.UpdateControlPosition(child);
void IQGLayer.UpdateControlSize(IQGControl child) { this.UpdateControlPosition(child); }