How to redraw or refresh in OnRender?

c#, drawing, onrender, wpf

Solution

Your question is not clear but from what I can understand you seem to be asking for a method to refresh the visuals after updating your drawing variables. You could use the following after updating your drawing variables:

this.InvalidateVisual();

and with the property:

private int drawItem;
pulic int DrawItem
{
 get {return drawItem;}
 set 
 {
    drawItem=value;
    this.InvalidateVisual();
 }
}

Problem

I want to draw something dynamically. Following code shows my OnRender. I'm setting DrawItem somewhere in my program where I need it. But when I'm calling `DrawItem =5;` what do I have to call, so that OnRender gets called? ``` protected override void OnRender(DrawingContext drawingContext) { switch (DrawItem) { case 1: //Draw Item break; case 2: //Draw Item break; case 3: //Draw Item break; case 4: //Draw Item break; case 5: //Draw Item break; } base.OnRender(drawingContext) } public int DrawItem { get; set; } ```

Original source