Feeds:
Posts
Comments

Posts Tagged ‘DrawingVisual’

The most important part of my drawing engine is almost done. In this post, I will talk about a coding mistake that took me almost a day to resolve hoping this will save some precious time to others. I spent a couple of hours adding a new renderer to my GIS application capable of drawing¬†custom data layers. Done with implementing all drawing steps and got to display the final result and… Nothing on the screen!

Here is a code sample, part of the new rendering class

public DrawingVisual Render(Geometry geo){
      DrawingVisual drawingVisual = new DrawingVisual();
      DrawingContext drawingContext = drawingVisual.RenderOpen();
      // Draw geometry
      drawingContext.DrawGeometry(Brushes.Red, new Pen(Brushes.Blue, 2), geom);
      return drawingVisual;
}

This bit of code does obviously not work! Every thing seems to be right in place but something hidden somewhere is wrong making the shapes not to appear on the screen.
In fact, there was one line missing! The drawing context was left open and that is the reason why my drawings were not reflected on the screen.
I fixed the issue by adding the following line at the end of the “Render” method.

      drawingContext.Close();

Read Full Post »