Method OnDrawingContent
OnDrawingContent(DrawContext?)
Called when the View's content is to be drawn. The default implementation does nothing.
protected virtual bool OnDrawingContent(DrawContext? context)
Parameters
contextDrawContextThe draw context to report drawn areas to.
Returns
Remarks
Override this method to draw custom content for your View.
Transparency Support: If your View has ViewportSettings with Transparent
set, you should report the exact regions you draw to via the context parameter. This allows
the transparency system to exclude only the drawn areas from the clip region, letting views beneath show through
in the areas you didn't draw.
Use AddDrawnRectangle(Rectangle) for simple rectangular areas, or AddDrawnRegion(Region) for complex, non-rectangular shapes. All coordinates passed to these methods must be in screen-relative coordinates. Use ViewportToScreen(in Rectangle) or ContentToScreen(in Point) to convert from viewport-relative or content-relative coordinates.
Example of drawing custom content with transparency support:
protected override bool OnDrawingContent (DrawContext? context)
{
base.OnDrawingContent (context);
// Draw content in viewport-relative coordinates
Rectangle rect1 = new Rectangle (5, 5, 10, 3);
Rectangle rect2 = new Rectangle (8, 8, 4, 7);
FillRect (rect1, Glyphs.BlackCircle);
FillRect (rect2, Glyphs.BlackCircle);
// Report drawn region in screen-relative coordinates for transparency
if (ViewportSettings.HasFlag (ViewportSettingsFlags.Transparent))
{
Region drawnRegion = new Region (ViewportToScreen (rect1));
drawnRegion.Union (ViewportToScreen (rect2));
context?.AddDrawnRegion (drawnRegion);
}
return true;
}