Choose between drawing and figure in WPF

I'm not quite sure of the differences between the System.Windows.Media.Drawing and System.Windows.Shapes.Shape classes. They both reveal the functionality associated with 2D graphics in WPF. When will you select it in your WPF application and when will you choose another?

+7
source share
1 answer

A Shape inherits from FrameworkElement and, therefore, is a high-level object that provides features such as hit-testing, styling, layout and data binding. In contrast, Drawing does not inherit from FrameworkElemet and does not support any of these functions. Since the documentation mentions that Drawing is useful for light visual objects. If you create a complex brush to paint areas or backgrounds, DrawingBrush will be very effective.

Drawings can combine text, video, images and Geometry objects (another light weight) to create complex, but very effective and fast drawings,

In short, a Drawing is an alternative to Shape at a low level. As for use cases, it depends.

  • If you need to animate or make any bindings, you should use Shapes.
  • If you are creating brushes or complex graphics / vector graphics, you are likely to use drawings.
  • Also, if you draw things by overriding OnRender , you mostly use Geometries.

A Drawing also Freezable and therefore can be split between threads (provided that it is frozen).

+9
source

All Articles