将大型C#winforms应用程序升级到WPF的最简单方法是什么?

时间:2022-09-21 14:07:24

I work on a large C# application (approximately 450,000 lines of code), we constantly have problems with desktop heap and GDI handle leaks. WPF solves these issues, but I don't know what is the best way to upgrade (I expect this is going to take a long time). The application has only a few forms but these can contain many different sets of user-controls which are determined programatically.

我在一个大型的C#应用​​程序(大约450,000行代码)上工作,我们经常遇到桌面堆和GDI处理泄漏的问题。 WPF解决了这些问题,但我不知道升级的最佳方法是什么(我预计这需要很长时间)。应用程序只有几种形式,但这些形式可以包含许多不同的用户控件集,这些用户控件是以编程方式确定的。

This is an internal company app so our release cycles are very short (typically 3 week release cycle).

这是一个内部公司应用程序,因此我们的发布周期非常短(通常为3周发布周期)。

Is there some gradual upgrade path or do we have to take the hit in one massive effort?

是否有一些渐进的升级路径,或者我们是否必须付出巨大的努力?

5 个解决方案

#1


11  

You can start by creating a WPF host.

您可以从创建WPF主机开始。

Then you can use the <WindowsFormHost/> control to host your current application. Then, I suggest creating a library of your new controls in WPF. One at a time, you can create the controls (I suggest making them custom controls, not usercontrols). Within the style for each control, you can start with using the <ElementHost/> control to include the "old" windows forms control. Then you can take your time to refactor and recreate each control as complete WPF.

然后,您可以使用 控件来托管当前的应用程序。然后,我建议在WPF中创建一个新控件的库。一次一个,您可以创建控件(我建议将它们设置为自定义控件,而不是用户控件)。在每个控件的样式中,您可以使用 控件来包含“旧”窗体控件。然后,您可以花时间重构并重新创建每个控件作为完整的WPF。

I think it will still take an initial effort to create your control wrappers and design a WPF host for the application. I am not sure the size of the application and or the complexity of the user controls, so I'm not sure how much effort that would be for you. Relatively speaking, it is significantly less effort and much faster to get you application up and running in WPF this way.

我认为仍然需要最初的努力来创建控件包装器并为应用程序设计WPF主机。我不确定应用程序的大小和用户控件的复杂程度,所以我不确定会给你多少努力。相对而言,以这种方式在WPF中启动和运行应用程序的工作量要少得多,而且速度要快得多。

I wouldn't just do that and forget about it though, as you may run into issues with controls overlaying each other (Windows forms does not play well with WPF, especially with transparencies and other visuals)

我不会那样做而忘记它,因为你可能会遇到控件相互叠加的问题(Windows窗体与WPF不兼容,尤其是透明胶片和其他视觉效果)

Please update us on the status of this project, or provide more technical information if you would like more specific guidance. Thanks :)

如果您需要更具体的指导,请向我们提供有关此项目状态的最新信息,或提供更多技术信息。谢谢 :)

#2


3  

Do you use a lot of User controls for the pieces? WPF can host winform controls, so you could piecewise bring in parts into the main form.

你是否对这些作品使用了很多用户控件? WPF可以托管winform控件,因此您可以将部分分段引入主窗体。

#3


2  

WPF allows you to embed windows forms user controls into a WPF application, which may help you make the transition in smaller steps.

WPF允许您将Windows窗体用户控件嵌入到WPF应用程序中,这可以帮助您以较小的步骤进行转换。

Take a look at the WindowsFormsHost class in the WPF documentation.

看一下WPF文档中的WindowsFormsHost类。

#4


2  

I assume that you are not just looing for an ElementHost to put your vast Winforms app. That is anyway not a real porting to WPF. Consider the answers on this Thread What are the bigger hurdles to overcome migrating from Winforms to WPF?, It will be very helpfull.

我假设您不仅仅是在寻找一个ElementHost来放置你庞大的Winforms应用程序。无论如何,这不是WPF的真正移植。考虑这个问题的答案克服从Winforms迁移到WPF的更大障碍是什么?这将是非常有帮助的。

#5


1  

There is a very interesting white paper on migrating a .NET 2.0 winform application toward WPF, see Evolving toward a .NET 3.5 application

有一篇关于将.NET 2.0 winform应用程序迁移到WPF的非常有趣的白皮书,请参阅演进到.NET 3.5应用程序

Paper abstract: In this paper, I’m going to outline some of the thought processes, decisions and issues we had to face when evolving a Microsoft .NET application from 1.x/2.x to 3.x. I’ll look at how we helped our client to adopt the new technology, and yet still maintained a release schedule acceptable to the business.

论文摘要:在本文中,我将概述在将Microsoft .NET应用程序从1.x / 2.x发展为3.x时我们必须面对的一些思考过程,决策和问题。我将看看我们如何帮助我们的客户采用新技术,但仍然保持了业务可接受的发布时间表。

#1


11  

You can start by creating a WPF host.

您可以从创建WPF主机开始。

Then you can use the <WindowsFormHost/> control to host your current application. Then, I suggest creating a library of your new controls in WPF. One at a time, you can create the controls (I suggest making them custom controls, not usercontrols). Within the style for each control, you can start with using the <ElementHost/> control to include the "old" windows forms control. Then you can take your time to refactor and recreate each control as complete WPF.

然后,您可以使用 控件来托管当前的应用程序。然后,我建议在WPF中创建一个新控件的库。一次一个,您可以创建控件(我建议将它们设置为自定义控件,而不是用户控件)。在每个控件的样式中,您可以使用 控件来包含“旧”窗体控件。然后,您可以花时间重构并重新创建每个控件作为完整的WPF。

I think it will still take an initial effort to create your control wrappers and design a WPF host for the application. I am not sure the size of the application and or the complexity of the user controls, so I'm not sure how much effort that would be for you. Relatively speaking, it is significantly less effort and much faster to get you application up and running in WPF this way.

我认为仍然需要最初的努力来创建控件包装器并为应用程序设计WPF主机。我不确定应用程序的大小和用户控件的复杂程度,所以我不确定会给你多少努力。相对而言,以这种方式在WPF中启动和运行应用程序的工作量要少得多,而且速度要快得多。

I wouldn't just do that and forget about it though, as you may run into issues with controls overlaying each other (Windows forms does not play well with WPF, especially with transparencies and other visuals)

我不会那样做而忘记它,因为你可能会遇到控件相互叠加的问题(Windows窗体与WPF不兼容,尤其是透明胶片和其他视觉效果)

Please update us on the status of this project, or provide more technical information if you would like more specific guidance. Thanks :)

如果您需要更具体的指导,请向我们提供有关此项目状态的最新信息,或提供更多技术信息。谢谢 :)

#2


3  

Do you use a lot of User controls for the pieces? WPF can host winform controls, so you could piecewise bring in parts into the main form.

你是否对这些作品使用了很多用户控件? WPF可以托管winform控件,因此您可以将部分分段引入主窗体。

#3


2  

WPF allows you to embed windows forms user controls into a WPF application, which may help you make the transition in smaller steps.

WPF允许您将Windows窗体用户控件嵌入到WPF应用程序中,这可以帮助您以较小的步骤进行转换。

Take a look at the WindowsFormsHost class in the WPF documentation.

看一下WPF文档中的WindowsFormsHost类。

#4


2  

I assume that you are not just looing for an ElementHost to put your vast Winforms app. That is anyway not a real porting to WPF. Consider the answers on this Thread What are the bigger hurdles to overcome migrating from Winforms to WPF?, It will be very helpfull.

我假设您不仅仅是在寻找一个ElementHost来放置你庞大的Winforms应用程序。无论如何,这不是WPF的真正移植。考虑这个问题的答案克服从Winforms迁移到WPF的更大障碍是什么?这将是非常有帮助的。

#5


1  

There is a very interesting white paper on migrating a .NET 2.0 winform application toward WPF, see Evolving toward a .NET 3.5 application

有一篇关于将.NET 2.0 winform应用程序迁移到WPF的非常有趣的白皮书,请参阅演进到.NET 3.5应用程序

Paper abstract: In this paper, I’m going to outline some of the thought processes, decisions and issues we had to face when evolving a Microsoft .NET application from 1.x/2.x to 3.x. I’ll look at how we helped our client to adopt the new technology, and yet still maintained a release schedule acceptable to the business.

论文摘要:在本文中,我将概述在将Microsoft .NET应用程序从1.x / 2.x发展为3.x时我们必须面对的一些思考过程,决策和问题。我将看看我们如何帮助我们的客户采用新技术,但仍然保持了业务可接受的发布时间表。