WPF is not as prone to drawing as Windows Forms. WPF is more content oriented.
The best way to draw is to create a map from existing WPF elements. For example, you can use Grid or UniformGrid or even Canvas to host your content. You can programmatically add Image and Rectangle to the map without worrying about any drawing code.
Here is an example:
UniformGrid grid = new UniformGrid(); grid.Columns = 10; grid.Rows = 10; grid.Width = columnWidth * 10; grid.Height = rowHeight * 10; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { if (fields[x, y] is SomeImage) { Image img = new Image(); img.Source = someImageSource; grid.Children.Add(img); } else { Rectangle rect = new Rectangle(); rect.Fill = someColor; grid.Children.Add(rect); } } } Canvas.SetLeft(grid, (canvas.Width - grid.Width) / 2); Canvas.SetTop(grid, (canvas.Height - grid.Height) / 2); canvas.Children.Add(grid);
You probably wonβt be able to use it as is, but you can fill in the missing pieces.
I recently did a project like this, using Canvas to place TextBlock s, Line and Button s. It is efficient and simple, much more than I expected.
source share