C#WPF OnPaint方法的选择吗? [英] C# WPF OnPaint method alternative?

查看:250
本文介绍了C#WPF OnPaint方法的选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在每当在这里或那里做一个小游戏的C#的WinForms,我会写了快班,这是一个子类System.Windows.Forms.Panel,并在构造函数中,设置DoubleBuffered为true。然后,你可以重写显示游戏元素OnPaint方法。我这样做2到3年了,但我真的想拥抱WPF和XAML,我真的很喜欢它的常规应用程序布局。 ?相当于什么有在WPF这样

In C# WinForms whenever making a small game here or there, I would write up a quick class that was a subclass to System.Windows.Forms.Panel and in the constructor, setting DoubleBuffered to true. Then you could override the OnPaint method to display game elements. I've done this for 2 or 3 years now, but I'm really trying to embrace WPF and XAML, I really like it for regular application layouts. What equivalent is there to doing this in WPF?

推荐答案

不是答案你寻找,但:你不应该为使用WPF游戏。使用表单棒(将不会被MS倾倒,因为WPF不会取代形式),或尝试XNA,如果你想要去到一个新的水平。

Not the answer you seek, but: you shouldn't use WPF for games. Stick with Forms (which won't be dumped by MS, since WPF isn't superseding Forms) or try XNA if you want to go to the next level.

更新:我很快昨天回答了这个问题,因为我很着急,,因为我也看了成WPF以做游戏,所以我并没有想离开OP没有合适的答案。

UPDATE: I answered the question very quickly yesterday, because I was in a hurry and because I also looked into WPF in order to do games, so I didn't wanted to left the OP without the proper answer.

下面是处理:

WPF目标是简化丰富的用户界面开发。首先,MS了解,编码组合的形式方式的行为的用的演示的。这是不好的,无论是应用程序设计为可维护性。此外,在形式,一切都要编码;库本身确实非常少的用户。例如,如果你想有一个不同的外观一个按钮,你必须覆盖其绘图方法,然后,不知何故,画什么图形表示它。

WPF goal is to simplify rich UI development. First, MS understood that Forms way of coding mix behavior with presentation. This is bad, both for application design as for maintainability. Besides, in Forms, everything has to be coded; The library itself does very little for the user. For example, if you want a button that has a different look, you have to override its Draw method and then, somehow, draw whatever graphic that represents it.

通过WPF,的行为的是从的表示分离的。例如,什么是按钮?在Windows中,我们知道它是一个带圆角的框,但环顾四周...鼠标滚轮也是一个按钮,即使它看上去一点也不像Windows的默认按钮。作为一个按钮,是指具有特定行为(点击,大部分),不仔细看像一个盒子。使用WPF,这是很简单的。你定义一个按钮,然后使用,也就是说,图像或文字,把它呈现给用户。

With WPF, behavior is separated from the presentation. For example, what is a button? In windows, we know it to be a box with rounded corners, but look around... your mouse scroll is also a button, even though it looks nothing like the Windows default button. Being a button means having a specific behavior (clicking, mostly), not looking like a box. With WPF, this is very simple. You define a button and then use, say, an image or a text, to present it to the user.

这一切是有代价的,当然,例如,WPF比形式更慢。游戏必须要快,尽量不浪费资源。在游戏中,每一个行为往往是编码的(不是UI,当然),各种演示定制(二维图形或3D对象),所以你必须做很多反正编码。所以,你正在使用的昂贵的技术,但大多数扔它的好处了。

All this comes at a cost, of course; for example, WPF is slower than Forms. Games need to be quick and try not to waste resources. In games, every behavior tends to be coded (not the UI, of course), every presentation is customized (a 2D graphic or a 3D object), so you will have to do a lot of coding anyway. So you are using an expensive technology but throwing away most of its benefits.

但我不是专家。您可以检查这个博客,其中一名前微软员工试过了,近两年来,使用WPF游戏。他的结论是:

But I'm no specialist. You can check this blog, where an ex-Microsoft employee tried, for almost two years, to use WPF for games. And he concludes:

您可能已经注意到,该博客
并没有在一段时间更新。 WPF
的表现似乎并不为
那里严肃游戏,我已经
在毛巾抛出使用XNA
比赛将正常工作。我只是不认为
这是值得战斗WPF
框架...

You've probably noticed that the blog hasn't been updated in a while. WPF performance just doesn't seem to be there for serious games, and I've thrown in the towel and will work on games using XNA. I just don't think it's worth fighting the WPF framework...

从那里我'已经得出了我的大部分结论。

From there I've drawn most of my conclusions.

这篇关于C#WPF OnPaint方法的选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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