How should I draw text and shapes in wpf and c #?

I want to make basic WPF graphics, i.e. Rectangles, lines, circles and text.

When should I use Drawing and when should I use DrawingVisual?

I have a code that uses Drawing, and I render them in DrawingImage and display it in the image control. Is it correct? I could not figure out how to add text to the drawing. I also had problems with positioning. Should I be rendering on canvas?

I have code that uses DrawingVisual and writes to a DrawingContext. This is similar to WinForms. Is this the recommended way?

Do you have any high level advice on using the API for basic graphics and shortcuts? Will they work on Silver Light and Desktop?

+3
source share
2 answers

In your comment, you mentioned that you are actually using scatterplots or similar plots. Typically, in WPF, this is created by templating existing controls, such as listview. It sounds illogical, but it is much simpler and more powerful than drawing.

This article by Charles Petzold shows a scatter plot implemented in this way and details how to make it more successful for 10,000+ data points.

+2
source

Most likely, you just want to make a Canvas. If you add “shapes” to the canvas, WPF will process the entire drawing for you.

See Forms and the main drawing in WPF for more details .

+1
source

Source: https://habr.com/ru/post/1749685/


All Articles