本文介绍了WPF canvas绘图与图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我想询问是否有可能使用某种图形类型在WPF Canvas上绘制,提供类似的方法: DrawLine,DrawPath 等..(就像在.NET 2中一样)。

  1. I'd like to ask if there is any possibility to draw on WPF Canvas with some kind of a Graphics type providing methods like: DrawLine, DrawPath etc.. (as it was in .NET 2).

很多东西喜欢故事板等等,但我计划做所有的代码背后的绘图和只有1 Canvas在WPF没有任何子元素

I know there's a lot of stuff like storyboards etc.. but I'm planning to do all the drawing in code behind and to have just 1 Canvas in WPF without any child elements.


  1. 你认为这是个好主意吗?是否平滑?


推荐答案

是的,您需要使用类

Yes, you need to use the DrawingContext class

这很难说,取决于你的确切需求...如果画布没有任何孩子项目,我认为一个更好的解决方案是创建一个自定义控件,并覆盖 OnRender 方法。关于平滑度,这一切都取决于你如何实现...

That's hard to tell, depending on your exact needs... If the canvas doesn't have any child items, I think a better solution would be to create a custom control and override the OnRender method. Regarding smoothness, it all depends on how you implement it...

这篇关于WPF canvas绘图与图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:17