none
How to force a redraw? Or how to get DrawingContext? RRS feed

  • Question

  • Hi!

    I need to perform some drawing on some event in my custom control derived from Canvas. How can I call OnRender() whenever I want? Or, how can I get the DrawingContext object to draw on top of the canvas not inside of OnRender()?

    I've read about DrawingVisual, but it's not UIElement and I can't add to the Children collection...

     

    Could anyone help me?

    Thursday, August 30, 2007 11:49 AM

Answers

  • Hello, any reason why you have to use DrawingContext? You can simply add some LineGeomerties to Canvas.Children. They’ll automatically be drawn. Don’t worry, it won’t be slow as long as you have hardware accelerated. WPF is capable of drawing thousands or even millions of simple visuals like lines very fast.

     

    Monday, September 3, 2007 4:57 AM

All replies

  • this sample in sdk might help

    ms-help://MS.MSDNQTR.v90.en/wpf_samples/local/samplehtmlsources/GraphicsMM/DrawingVisualSample/CSharp/Window1.xaml.cs.htm

     

    Thursday, August 30, 2007 12:22 PM
    Moderator
  • Thank you for help, lee d!

    It should help solving my problem. But the sample uses the class, that "provides layout, event handling, and container support for the child visual objects". Wouldn't it be slow? Isn't there anything 'lighter'? I just need to draw a few lines, but not only when OnRender() is called.

    Creating a visual for each line (emulating drawing) seems to be resource-consuming as well.

    Also, their MyVisualHost overrides methods to access the collection of its children. All this seems to be too bulky, or am I wrong and this is the only way?

    Thursday, August 30, 2007 12:55 PM
  • Hello, any reason why you have to use DrawingContext? You can simply add some LineGeomerties to Canvas.Children. They’ll automatically be drawn. Don’t worry, it won’t be slow as long as you have hardware accelerated. WPF is capable of drawing thousands or even millions of simple visuals like lines very fast.

     

    Monday, September 3, 2007 4:57 AM
  • Thanks, now I'm informed Smile

    Will draw using LineGeometries.

    And is there any performance difference (or any other kind of difference) if I draw Line objects instead of LineGeometry objects?

     

    Monday, September 3, 2007 3:02 PM
  • Hello,

    I try this sample but in my way it doesn't force a redraw.

    I have to display a rectangle and when changing its size, be able to force the WPF application to redraw the control.
    I need to do this to avoid the application to redraw the entire window when two rectangles are localized at top-left and bottom-right of the window.

    Do you have any idea to do it ?

    Thanks

    Mathieu Cans
    Tuesday, July 8, 2008 9:32 AM