简体   繁体   English

从Winforms迁移到WPF

[英]Migrating from Winforms to WPF

We have an old application built on .Net 1.1 Framework and Winforms. 我们有一个基于.Net 1.1 Framework和Winforms的旧应用程序。 We are planning to migrate it to the latest version of .Net. 我们正计划将其迁移到最新版本的.Net。

Here are some of the questions running in my mind: 这是我想到的一些问题:

  1. Should we go with Winforms or WPF? 我们应该选择Winforms还是WPF?
  2. We want the design and structure to the exact same as what we have now. 我们希望设计和结构与我们现在所拥有的完全相同。
  3. What kind of pitfalls can I expect when migrating? 我在迁移时会遇到什么样的陷阱?
  4. Is there any place where I can lookup to see the process of migration? 我可以在任何地方查看迁移过程吗?
  5. Any other suggestions? 还有其他建议吗?

Should we go with Winforms or WPF? 我们应该选择Winforms还是WPF?

This is a very broad question. 这是一个非常广泛的问题。 But my answer to that would be this. 但是我的答案是这样的。 Winforms designer is a painful experience and it is not as flexible as WPF by any means so if that is important to you then you should. Winforms设计师是一个痛苦的经历,无论如何它都不如WPF灵活,因此如果这对您很重要,则应该这样做。

We want the design and structure to the exact same as what we have now. 我们希望设计和结构与我们现在所拥有的完全相同。

Anything you do in Winforms you can replicate in WPF so no worries there. 您在Winforms中所做的任何事情都可以在WPF中复制,因此不必担心。

What kind of pitfalls can I expect when migrating? 我在迁移时会遇到什么样的陷阱?

There are too many to name one of the most common ones for our migration was converting existing logic in the WinForms (yes it was a crappy, outsourced, legacy WinForms full of business logic) and connecting it to WPF elements. 对于我们的迁移而言,有太多的最常见的方法之一就是转换WinForms中的现有逻辑(是的,这是一个充满业务逻辑的cr脚的,外包的,遗留的WinForms)并将其连接到WPF元素。 The process in and of itself is not that complicated but when you have too many intertwined pieces it can get pretty ugly. 这个过程本身并不复杂,但是当您有太多相互交织的片段时,它会变得很丑陋。

Is there any place where I can lookup to see the process of migration? 我可以在任何地方查看迁移过程吗?

The process of migration pretty much has to be iterative. 迁移过程几乎必须是迭代的。 So the way many people do it based on my research (articles, StackOverflow answers and such) is through ElementHosts. 因此,根据我的研究(文章,StackOverflow答案等),很多人都通过ElementHosts来做。

1) Target a certain part of your WinForms that you would like to switch up to WPF and then take it out. 1)定位WinForms中要切换到WPF的某个部分,然后将其取出。

2) Replace it with ElementHost. 2)将其替换为ElementHost。

3) Then in that ElementHost you will have your newly rewritten WPF counterpart. 3)然后在那个ElementHost中,您将拥有新重写的WPF副本。

4) Test it out make sure that it works okay with the rest of the elements. 4)测试一下,确保它与其余元素都可以正常工作。

5) Go to step 1 until rest of the stuff on that window is replaced (You can do header, middle, footer or top, bottom any way you wish to go about replacing elements on the window it depends on your particular situation). 5)转到步骤1,直到替换了该窗口上的其余内容(您可以根据自己的具体情况,选择要在窗口上替换元素的任何方式的页眉,中间,页脚或顶部,底部)。

6) Once most of the stuff is replaced you can then combine all of those WPF User Controls into a WPF Window. 6)一旦替换了大多数东西,您就可以将所有这些WPF用户控件组合到一个WPF窗口中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM