You should not use InvalidateVisual() unless the size of your control changes, since it causes a rather costly reinstallation of your user interface.
WPF is a saved drawing system. This means that OnRender() better called AccumulateDrawingObjects() . It actually accumulates a tree of living drawing objects, which should be executed only once for the layout. He then uses these objects to paint your user interface when necessary. To change how a part of the user interface looks like without re-arranging, some objects (for example, DrawingGroup, RenderTargetBitmap and WriteableBitmap) can be updated after OnRender() at any time convenient for you.
To update part of your interface later, wrap these commands in a DrawingGroup and place this object in a DrawingContext . You can then Open() and update it whenever you want, and WPF will automatically repaint 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