DrawLabelBackground ( DrawingContext oDrawingContext, GraphDrawingContext oGraphDrawingContext, FormattedText oFormattedText, Color oFormattedTextColor, Byte btBackgroundAlpha, Point oTextOrigin ) { Debug.Assert(oDrawingContext != null); Debug.Assert(oGraphDrawingContext != null); Debug.Assert(oFormattedText != null); AssertValid(); if (oFormattedText.Width == 0 || oFormattedText.Height == 0) { return; } // Note: Don't make the background any more opaque than the text, which // might be translucent itself. Color oBackgroundColor = WpfGraphicsUtil.SetWpfColorAlpha( oGraphDrawingContext.BackColor, Math.Min(btBackgroundAlpha, oFormattedTextColor.A)); SolidColorBrush oBackgroundBrush = CreateFrozenSolidColorBrush( oBackgroundColor); Rect oBackgroundRectangle = WpfGraphicsUtil.GetFormattedTextBounds( oFormattedText, oTextOrigin); // Draw a rounded rectangle with a small amount of padding. const Int32 Padding = 1; const Int32 Radius = 2; oBackgroundRectangle.Inflate(Padding, Padding); oDrawingContext.DrawRoundedRectangle(oBackgroundBrush, null, oBackgroundRectangle, Radius, Radius); }