GDI +和WPF的C#转换 [英] C# Transition between GDI+ and WPF

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

问题描述

林的考虑的使用自定义的GDI迁移我的C#应用​​程序+绘制控件使用自定义controlls等WPF应用程序,我想知道什么是参与和所期待的。

Im considering migrating my c# application from using custom GDI+ drawn controls to a WPF application with custom controlls etc. I would like to know whats involved and what to expect.

有没有人可以推荐,可能会帮助任何资源?或任何个人的经验,这可能是benificial?

Are there any resources people can recommend that might help? Or indeed any personal experiences that might be benificial?

推荐答案

(我提前道歉的长期职位...正好有这么多,我想传达...我希望它可以帮助你。)

这是我们现在正在做的事情(迁移Windows窗体应用大量使用自定义(GDI +)绘制控件到WPF)。事实上,我对球队的作用是建立这些GDI +的控制...现在打造的WPF的。

This is what we are doing now (migrating a Windows Forms application with heavy use of custom (GDI+) drawn controls to WPF). In fact, my role on the team was to build these GDI+ controls ... and now to build the WPF ones.

我同意Bijington这使应用程序完全100从地上爬起来%WPF是去......如果你能说服是走这条路的权力的方式。但是,我们自己要转换我们的Windows窗体就地应用,服用 WPF互操作能力。有一定的局限性,但总体来说一直是一个有效的方法(而不是沮丧,因为我本来期望)。

I agree with Bijington that making your application completely 100% WPF from the ground up is the way to go ... if you can convince the powers that be to go that route. However, we ourselves are converting our Windows Forms application in-place, taking advantage of the WPF interop capabilities. There are some limitations, but overall it has been an effective approach (and not as frustrating as I would have expected).

我的建议是,你把你的GDI +控件之一,并建立在WPF相同的控制。,然后,当你完成后,再扔掉它,做它。你总是会学到的第一个工作期间出现...并发现有更好的办法做到这一点吧。我会从一些小事开始......自定义按钮是开始的好地方。

What I would suggest is that you take one of your GDI+ controls and build the same control in WPF. And then, when you are finished, throw it away and do it again. You will invariably learn something during the first effort ... and discover that there is a better way to do it instead. I would start with something small ... a custom button is a good place to begin.

做上述会给你什么事情需要一个人的滋味一切你想做的事。

Doing the above will give you a taste for what is going to be required for everything else you want to do.

有一件事我想提醒你的是WPF的学习曲线,特别是如果你从Windows窗体来......背景,尤其是当您将要构建自定义寻找控制。正如安倍晋三所说,这是一个完全不同的世界。 WPF肯定带来了很大的权力,但这种权力正值学习如何使用它的代价。安倍提到在WPF自定义控件是如何'无外观',他们的'看'可以具有的ControlTemplate。这只是在WPF许多方面提供自定义寻找你的用户界面的作品之一

One thing I would warn you about is WPF's learning curve, especially if you are coming from a Windows Forms background ... and especially if you are going to be building custom looking controls. As Abe has mentioned, it is a completely different world. WPF definitely brings a lot of power, but that power comes at a cost of learning how to use it. Abe mentions how custom controls in WPF are 'lookless' and that their 'look' can be provided with a ControlTemplate. This is just one of many ways in WPF to provide custom looking pieces of your user interface.

让我列举其中的一些附加的方式:

Let me enumerate some of those additional ways:


  1. 样式使用WPF的造型能力的现有的控制。

  2. 充分利用WPF的自ContentControl派生内容模型和/或控制。这让你坚持随心所欲看内容到控制的视觉效果(例如,也许坚持一个自定义绘制的形状为一个按钮的中间)。

  3. 撰写控制了其他控制/通过利用UserControl的优势要素。

  4. 从在WPF现有的控件/类派生,扩展它的行为和提供的视觉效果不同的默认设置。

  5. 自FrameworkElement派生,创建自定义WPF元素,通过覆盖部分或全部的MeasureOverride,ArrangeOverride和OnRender方法的方法。

  6. 多....如果你能相信它。

  1. Style an existing control using the styling capabilities of WPF.
  2. Take advantage of WPF's content model and/or controls derived from ContentControl. This allow you to stick arbitrary looking 'content' into visuals of a control (e.g. maybe sticking a custom drawn shape into the middle of a button).
  3. Compose a control out of other controls/elements by taking advantage of UserControl.
  4. Derive from an existing control/class in WPF, extending it's behavior and providing a different default set of visuals.
  5. Derive from FrameworkElement, creating a custom WPF element, by overriding some or all of the MeasureOverride, ArrangeOverride, and OnRender methods.
  6. And more .... if you can believe it.

在Windows窗体,就好像他们给你一把锤子(UserControl的)和一把螺丝刀(控制)。然而,在WPF ...他们已经给你所有的工具100整个工具箱。这也是非正常的学习曲线的更大的部分原因。但是,现在你可以走,看到你从未有过的,用它来锯掉一个2X4的结束而不是使用锤子和/或螺丝刀,试图做同样的事情的。

In Windows Forms, it was like they gave you a hammer (UserControl) and a screwdriver (Control). However, in WPF ... they have given you the whole toolbox with all 100 tools. And this is part of the reason for the bigger than normal learning curve. However, now you can take that saw that you never had before and use it to saw off the end of a 2x4 instead of using the hammer and/or screwdriver to try and do the same thing.

(好消息是,有很多出去的资源在那里,可以帮助您。)


  1. 图书

    • 编程WPF由克里斯·塞尔斯和放大器;伊恩·格里菲思(特别是第18章)

    • 临WPF由马修·麦克唐纳(尤其是第24章)

    • WPF亚当森偷跑(以特别是第16章)

    • 应用程序=代码+标记由Charles Petzold的(特别是第10章,11,放大器; 12)

    • 基本WPF由克里斯·安德森(特别是第3章)搜索结果
      我最喜欢的书是查尔斯Petzold的书,亚当森的书。然而,塞尔斯和放大器编程WPF的第18章;格里菲思是主题的真正伟大的概述,并在问题的特别报道:我真的需要一个自定义控件

  1. Books
    • Programming WPF by Chris Sells & Ian Griffiths (in particular, chapter 18)
    • Pro WPF by Matthew MacDonald (in particular, chapter 24)
    • WPF Unleashed by Adam Nathan (in particular, chapter 16)
    • Applications = Code + Markup by Charles Petzold (in particular, chapters 10, 11, & 12)
    • Essential WPF by Chris Anderson (in particular, chapter 3)

      My favorite books are Charles Petzold's book and Adam Nathan's book. However, chapter 18 of Programming WPF by Sells & Griffiths is really great overview of the subject, and in particular coverage of the question: Do I really need a custom control?

  • WPF论坛

  • 计算器结果
    这里有两个特别的职位,你会想看看(的one ,的)。

  • The WPF Forum
  • StackOverflow
    Here are two posts in particular that you will want to take a look at (one, two).

MSDN 结果
我Bijington同意 MSDN文档优秀。

博客结果
在的我在论坛上面部分引用两个StackOverflow的职位之一,我点了一组我的'必读'名单上的博客。特别是,我要特别指出帕Podila 并的凯文·摩尔。凯文摩尔曾经是为WPF控件WPF程序经理,他有一个很好的一套名为 WPF袋-O-技巧这是有用的,但更重要的是,控制您可以从。

Blogs
In one of the two StackOverflow posts that I reference in the Forums section above, I point to a set of blogs on my 'must read' list. In particular, I would especially point to the blogs of Pavan Podila and Kevin Moore. Kevin Moore used to be the WPF program manger for the WPF controls and he has a nice set of controls called the WPF Bag-o-Tricks that are useful, but more importantly, controls that you can learn from.

样品,样品,以及更多的样本结果学习
只是有一吨的样品那里。几乎太多了!我想指出 Family.Show (这是为WPF一个终端到终端的参考样本创建)和我将指向 SDK示例的,特别是对的Control定制样品的该部分内。

Samples, Samples, and more Samples
There are just a ton of samples out there. Almost too many! I would point to Family.Show (it was created as an end-to-end reference sample for WPF) and I would point to the WPF SDK samples and in particular to the Control Customization samples within that section.

这篇关于GDI +和WPF的C#转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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