在 WPF 中选择绘图和形状
我不太确定 System.Windows.Media.Drawing 类和 System.Windows.Shapes.Shape 类之间的区别。它们都公开了与 WPF 中 2D 图形相关的功能。您什么时候会在 WPF 应用程序中选择一个,什么时候会选择另一个?
I am not quite sure about the differences between the classes System.Windows.Media.Drawing
and System.Windows.Shapes.Shape
. They both expose functionality related to 2D graphics in WPF. When would you choose one in your WPF application, and when would you choose the other?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Shape
继承自 FrameworkElement 因此是一个高级对象,提供命中测试、样式、布局和数据绑定等功能。相比之下, 绘图 不会继承自 < code>FrameworkElemet 并且不支持任何这些功能。正如文档提到的,Drawing
对于轻量级视觉对象很有用。如果您正在创建一个复杂的画笔来绘制区域或背景,那么 DrawingBrush 将非常有效。绘图可以组合文本、视频、图像和几何 对象(另一个轻量级类)来创建复杂但非常高效且快速的绘图。
简而言之,
Drawing
是Shape
的低级替代方案。至于用例,这取决于。
OnRender
来绘制东西,您主要会使用几何图形。Drawing
也是Freezable
,因此可以在线程之间共享(假设它被冻结)。A
Shape
inherits from FrameworkElement and is therefore a high level object which provides features such as hit-testing, styling, layout and data binding. In contrast a Drawing does not inherit fromFrameworkElemet
and doesn't support any of these features. As the documentation mentions aDrawing
is useful for lightweight visual objects. If you are creating a complex brush to use to paint areas or a background a DrawingBrush would be very efficient.Drawings can combine text, video, images and Geometry objects (another light weight class) to create complex but very efficient and fast drawings.
In short a
Drawing
is a low-level alternative to aShape
.As for use cases, it depends.
OnRender
you would mostly use Geometries.A
Drawing
is alsoFreezable
and can thus be shared among threads (assuming it is frozen).