/// <summary> /// 绘制控件 /// </summary> /// <param name="drawingContext"></param> protected override void OnRender(DrawingContext drawingContext) { if (Child != null) { Geometry cg = null; Brush brush = null; //DpiScale dpi = base.getd(); Pen pen = new Pen(); pen.Brush = this.BorderBrush; //pen.Thickness = BorderThickness * 0.5; pen.Thickness = AngleBorder.RoundLayoutValue(BorderThickness.Left, FrameworkElementExtend.DpiScaleX); switch (Placement) { case EnumPlacement.LeftTop: case EnumPlacement.LeftBottom: case EnumPlacement.LeftCenter: //生成小尾巴在左侧的图形和底色 cg = CreateGeometryTailAtLeft(); brush = CreateFillBrush(); break; case EnumPlacement.RightTop: case EnumPlacement.RightCenter: case EnumPlacement.RightBottom: //生成小尾巴在右侧的图形和底色 cg = CreateGeometryTailAtRight(); brush = CreateFillBrush(); break; case EnumPlacement.TopLeft: case EnumPlacement.TopCenter: case EnumPlacement.TopRight: //生成小尾巴在右侧的图形和底色 cg = CreateGeometryTailAtTop(); brush = CreateFillBrush(); break; case EnumPlacement.BottomLeft: case EnumPlacement.BottomCenter: case EnumPlacement.BottomRight: //生成小尾巴在右侧的图形和底色 cg = CreateGeometryTailAtBottom(); brush = CreateFillBrush(); break; default: break; } GuidelineSet guideLines = new GuidelineSet(); drawingContext.PushGuidelineSet(guideLines); drawingContext.DrawGeometry(brush, pen, cg); } }
private static double RoundLayoutValue(double value, double dpiScale) { double num; if (!AngleBorder.AreClose(dpiScale, 1.0)) { num = Math.Round(value * dpiScale) / dpiScale; if (double.IsInfinity(num) || AngleBorder.AreClose(num, 1.7976931348623157E+308)) { num = value; } } else { num = Math.Round(value); } return(num); }