It is very important to understand that WPF is not like Windows.Forms. OnRender() should really be called AccumulateDrawingObjects() , because that's what it does. WPF accumulates a bunch of drawing objects that it saves in order to be able to draw the user interface when necessary. The magic of effectively updating the user interface is that you can really change the objects in this visual tree after OnRender() .
For example, you can create a DrawingGroup and put it in a DrawingContext during OnRender . Then at any time when you want to change the visual, you can DrawingGroup.Open() , put new drawing commands in it, and WPF will effectively DrawingGroup.Open() this part of the user interface.
It looks like this:
DrawingGroup backingStore = new DrawingGroup(); protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); Render();
David jeske
source share