private void AddDotDensityLegendItems(LegendAdornmentLayer legendAdornmentLayer) { CustomDotDensityStyle dotDensityStyle = (CustomDotDensityStyle)currentStyleBuilder.GetStyles(currentFeatureLayer.FeatureSource)[0]; // Here we generate 4 legend items, for 5, 10, 20 and 50 points seperately. int[] pointCounts = new int[] { 5, 10, 20, 50 }; foreach (int pointCount in pointCounts) { LegendItem legendItem = new LegendItem(); legendItem.ImageMask = new AreaStyle(new GeoPen(GeoColor.StandardColors.LightGray, 1), new GeoSolidBrush(GeoColor.SimpleColors.Transparent)); legendItem.ImageWidth = 48; legendItem.TextTopPadding = 16; legendItem.TextRightPadding = 5; legendItem.BottomPadding = 16; legendItem.TopPadding = 16; legendItem.RightPadding = 5; CustomDotDensityStyle legendDotDensityStyle = (CustomDotDensityStyle)dotDensityStyle.CloneDeep(); legendDotDensityStyle.DrawingPointsNumber = pointCount; legendItem.ImageStyle = legendDotDensityStyle; string text = string.Format(CultureInfo.InvariantCulture, "{0:0.####}", TextFormatter.GetFormatedStringForLegendItem(dotDensityStyle.ColumnName, (pointCount / dotDensityStyle.PointToValueRatio))); legendItem.TextStyle = new TextStyle(text, new GeoFont("Segoe UI", 10), new GeoSolidBrush(GeoColor.SimpleColors.Black)); legendAdornmentLayer.LegendItems.Add(legendItem); } }