I'am creating CAD application using WPF. And I want to implement render loop like following
public class Editor
{
private DrawingGroup RenderGroup = new DrawingGroup();
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
var dc = drawingContext;
Render();
dc.DrawDrawing(RenderGroup);
}
void Render()
{
//All Render goes here, for example
for (int i=0; i<25;i++)
{
dc.DrawRenctagle.....
}
}
public Editor()
{
CompositionTarget.Rendering += CompositionTarget_Rendering;
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
Render();
}
}
I have no experience in wpf looping, this way seems to be working for me now. But I am curious if I will run into troubles in future. Is there a "best practice" for tasks like that?
p.s Alternative to that is calling Render() only when it's need, like when I'am moving something on control and there is real need to redraw things. But in future I want to implement some animation features, and without loop it will be more challenging