In my “game” I will draw a small map (i.e. 10×10 fields). Each field will represent a wall or ground. Depending on the answers to this question, the tiles will be either PNG images or simple color-filled rectangles.
What is your best recommended way to draw such a map in WPF? I want it to be as simple as possible, because the GUI part of this project is not very important, I just want it to be displayed in the center of the window.
Ideas that I have:
Canvas+ placing multipleRectangles as children- Bitmap rendered by engine, displayed by GUI
- External library?
WPF is not so inclined toward drawing as Windows Forms is. WPF is more content-oriented.
The best way to ‘draw’ something is to generate the map out of existing WPF elements. For example, you could use a
GridorUniformGrid, or even aCanvasto lay out your content. You could programmatically addImages andRectangles to the map, without worrying about any drawing code.Here is an example:
You probably won’t be able to use that as is, but you can fill in the missing pieces.
I recently did a project similar to this, using a
Canvasto lay outTextBlocks,Lines andButtons. It is efficient and simple, a lot more than I expected.