How to render bitmap into canvas in WPF?

void.pointer picture void.pointer · Jan 30, 2010 · Viewed 32.4k times · Source

I've subclassed Canvas so that I can override its Render function. I need to know how I can load a bitmap in WPF and render that to the canvas. I'm completely new to WPF and I haven't found any tutorials that show you how to do something so seemingly trivial. Step-by-step instructions with examples would be great.

Answer

user7116 picture user7116 · Jan 30, 2010

In WPF it is a rare case that you would need to override OnRender especially if all you wanted to do was draw a BMP to a background:

<Canvas>
    <Canvas.Background>
        <ImageBrush ImageSource="Resources\background.bmp" />
    </Canvas.Background>
    <!-- ... -->
</Canvas>