Tech Off Post

Single Post Permalink

View Thread: I always get a black backgraound with DrawingContext in WPF
  • User profile image

    I think my real question is what I am really drawing on. It seems to not be the window object. I don't know what the DrawingContext actually is and where it fits in

    Well, yes, you're not drawing on the window but on those drawing visuals and they are the children (in the visual tree) of the window. DrawingContext stores the drawing commands and then it is closed (by means of using in this case) the stored commands become the content of the visual. Note that these drawing commands are not part of either the visual or logical tree.

    It's also possible to draw directly on the window in the OnRender method but you need to set the window's template to an empty ControlTemplate, otherwise the template will show on top of your drawing and you won't see anything.