从 Windows 窗体迁移到 WPF ......值得吗? [英] Migrating from Windows Forms to WPF... was it worth it?

查看:30
本文介绍了从 Windows 窗体迁移到 WPF ......值得吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还有一个用 Windows 窗体编写的桌面应用程序,它的大小适中(数据库中有 46 个表支持几十个主要窗体).我正在考虑在 WPF 中重写 UI,但在我去那里之前,我很好奇是否有任何关于进行这种转换的战争故事.

I also have a desktop application written in Windows Forms that is a middling size (a couple dozen major forms backed by 46 tables in the database). I'm thinking about rewriting the UI in WPF, but before I go there I was curious if there were any war stories about doing such a conversion.

我使用 LLBLGen 来生成我的低级数据访问对象,并且我有一个业务逻辑在那上面的层.表单数据绑定到业务逻辑对象,尽管主表单使用缓存对象来最小化更常见导航路线上的往返行程.UI 从不直接与数据库对话:总是通过 UI -> 业务逻辑 -> 低级 -> 数据存储路径.

I use LLBLGen to generate my low level data access objects, and I have a business logic layer above that. The forms are databound to the business logic objects, although the main form uses caching objects to minimize round trips on the more common navigation routes. The UI never speaks directly to the database: always through the UI -> business logic -> low level -> datastore path.

我经常使用的一个控件是 TreeView,它充当视觉指南和短程导航工具.树已经用图标、高亮颜色进行了大量定制,它是我最担心移植的控件.

One control that I use heavily is the TreeView, which acts as a visual guide and short range navigation tool. The tree has been heavily customized with icons, highlight colors and it is the control I worry most about porting.

是否有故事可以说服我继续进行转换(或者相反,等到 Microsoft 更接近于从 Windows 窗体下撤出地毯)?

Is there a story that might convince me to go ahead and convert (or conversely, wait until Microsoft is closer to pulling the rug out from under Windows Forms)?

在评论中有人问我转换的动机是什么.我对未来的证明有些担忧:我有 500,000 行代码,它们最初是 ASP 和 VBScript.随着时间的推移,我们一直在将功能移植到 ASP.NET 和 C#,但仅限于对代码进行更改时.好处是我们将成本降至最低,坏处是一半的代码仍然是 ASP 和 VBScript.我担心 Windows 窗体应用程序会出现类似的情况.

I was asked in a comment what motivation for conversion I have. I have some concern about future proofing: I have 500,000 lines of code that were originally ASP and VBScript. We have been porting the functionality over time to ASP.NET and C#, but only as we make changes to the code. The upside is we have kept costs minimized, the downside is half the code remains ASP and VBScript. I'm concerned about a similar situation arising with Windows Forms applications.

我是否担心今天 Windows 窗体会消失?甚至不接近它......但是该应用程序正在从 ASP 和 VBScript 转移到 ASP.NET 和 C#,它背后有九年的历史,并且可能不会在这十年被取代(相反,它只是会发展).桌面应用程序同样是一个具有多年历史的长期项目.

Am I worried today about Windows Forms going away? Not even close to it... but the application is moving from ASP and VBScript to ASP.NET and C#, has nine years of history behind it, and probably won't be replaced this decade (instead, simply it will evolve). The desktop application is likewise a long term project with years of history.

推荐答案

WPF 很棒.它特别适用于使用自定义扩展 TreeView 等控件.您可以将字符串添加为 TreeControl 中的项目.您还可以添加一个包含各种字体和颜色的图像和一些文本的小面板.或者您可以添加按钮或任何您喜欢的东西.它有一个完全通用的可组合性系统.ListBox、ComboBox、Button 等也是如此.它们的所有内容或子项可以像字符串一样简单,也可以像带有缩放按钮的多页文档查看器一样复杂(如果需要).

WPF is great. It is particularly good for extending controls like TreeView with customisations. You can add a string as an item in a TreeControl. You can also add a small panel containing an image and some text in various fonts and colours. Or you can add buttons, or anything you like. It has a completely general composability system. Same goes for ListBox, ComboBox, Button, etc. All their content or child items can be as simple as a string or as complex as a multipage document viewer with zoom buttons (if you want).

但是找出答案的唯一方法是尝试移植您的一个表单.从现有应用程序中打开 WPF 窗口应该不会太难.我通过制作托管在 C++ Win32 应用程序中的新 GUI 面板开始使用 WPF.最终很明显 WPF 是要走的路,我们改变了它并制作了外壳 WPF,一些古老的对话框仍然由旧的 C++ 代码实现,我们无法费心重写它们(可能正是Visual Studio 2010 会发生).

But the only way to find out is to try porting one of your forms. It shouldn't be too hard to make a WPF Window open from within your existing app. I started using WPF by making new GUI panels that were hosted inside a C++ Win32 application. Eventually it was so obvious that WPF was the way to go that we switched it around and made the outer shell WPF, with some ancient dialog boxes still implemented by the old C++ code where we couldn't be bothered to rewrite them (probably exactly what will happen with Visual Studio 2010).

这篇关于从 Windows 窗体迁移到 WPF ......值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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