WPF canvas绘图与图形 [英] WPF canvas drawing with Graphics

查看:2427
本文介绍了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. 你认为这是个好主意吗?是否平滑?


推荐答案


请问是否有任何可能性在绘制WPF Canvas与某种图形类型提供的方法像DrawLine,DrawPath等..(因为它是在.NET 2)。

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).

是的,您需要使用 DrawingContext

Yes, you need to use the DrawingContext class


这是个好主意?它会很流畅吗?

Do you think it is a good idea? will it be smooth ?

这很难说,取决于你的确切需求...如果画布没有任何孩子项目,我认为一个更好的解决方案是创建一个自定义控件,并覆盖 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绘图与图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆