简体   繁体   English

是否可以在不更改现有代码的情况下在已经开发的C#Windows窗体应用程序中实现WPF?

[英]Is it possible to implement WPF in already developed C# Windows form application Without Changing Existing code?

i am working with C# windows form application i developed project in that.i like to make project design into more stylish and modern.is it possible to do like this by using WPF,if yes i like to apply WPF code without change Existing code and design,Is it possible to do like this. 我正在使用C#Windows窗体应用程序开发项目,因此我希望使项目设计更加时尚和现代。是否可以通过使用WPF来做到这一点,如果是的话,我希望不更改现有代码即可应用WPF代码设计,是否有可能这样做。

For Example i am putting one button name OK if i click OK i show hai in Message Box but my button view is just usual one i like to change the button stylish using WPF without changing that click event. 例如,如果我单击“确定”,我将一个按钮名称确定为“ OK”,我在消息框中显示hai,但我的按钮视图只是通常的一个,我想使用WPF更改按钮的样式而不更改该单击事件。

if you wanna use WPF styles in a Window Form app, its not possible but you can use a WPF Host in your window form app and add your WPF user controls in that and get more or less the view you are looking for... 如果您想在Window Form应用程序中使用WPF样式,那是不可能的,但是您可以在Window Form应用程序中使用WPF Host并在其中添加WPF用户控件,从而获得或多或少的所需视图...
take a look at here : Host a WPF Control in a Win32 Application 在这里看看: 在Win32应用程序中托管WPF控件

Windows forms is not WPF and WPF is not windows forms. Windows窗体不是WPF,WPF不是Windows窗体。 You can NOT "style" a winforms application, at least, not easily. 至少,这不容易,您不能“样式化” winforms应用程序。 You would have to use some kind of "skinning" library. 您将不得不使用某种“皮肤”库。 In most cases, your non-UI code from your winforms app can be used in the WPF app. 在大多数情况下,可以在WPF应用程序中使用Winforms应用程序中的非UI代码。 For example, a SOAP web service or WCF service. 例如,SOAP Web服务或WCF服务。

You can, in some cases, put a WPF control in your windows form app, and vice versa. 在某些情况下,您可以将WPF控件放入Windows窗体应用程序中,反之亦然。 it would be like taking your windows form app and putting in ASP.NET. 就像将您的Windows窗体应用程序放入ASP.NET。 You are talking about 2 different platforms. 您正在谈论2个不同的平台。

To make these sort of architecture changes you would need to refactor all your logic away from the UI, and then rewrite the UI on top of a business or service layer. 要进行这类体系结构更改,您需要将所有逻辑从UI重构出来,然后在业务或服务层之上重写UI。

As an example, your click event would need to have its code removed and moved to a Amodel or viewmodel, and perhaps replace the Message box with a call to a message box service, which could be stubbed for testing. 例如,您的click事件将需要删除其代码并将其移至Amodel或viewmodel,并且可能用对消息框服务的调用来替换“消息框”,可以将其存根进行测试。

This sort of refactoring can be done slowly using the technique described by Dr TJ, or you could spend your time refactoring code out of your UI layer, and then replace the UI layer in one hit later. 可以使用TJ博士描述的技术来缓慢地进行这种重构,或者您可以花时间在UI层之外重构代码,然后在以后的一击中替换掉UI层。

因此,改写一下:您想更改程序而不更改程序吗?

暂无
暂无

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

相关问题 UI 自动化使用 Selenium c# 用于 Windows 应用程序开发使用 Z3055DD731D79EAA7189A62F36724EEF09 应用程序框架 - UI Automation using Selenium c# for Windows App developed with WPF application with CEF framework 如何在C#中将WPF窗体设置为Windows窗体应用程序主窗体 - how to set wpf form as windows form application mainform in c# 如何部署使用sql server express 2012和crystal report开发的C#windows表单应用程序 - how to deploye C# windows form application developed with sql server express 2012 and crystal report C#WPF应用程序在已开发的计算机上运行,​​但在其他任何地方都无法运行 - C# WPF Application runs on the developed Computer but not any where else C#和HTML:如何为Windows窗体到html实现一个已创建的C#类? - C# and Html: How to implement an already created C# class for windows form to html? 在 C# windows 应用程序窗体中按住它的同时更改按钮设计 - Changing button design while holding it in C# windows application form 用 C# 开发的 Windows 服务应用程序的用例图 - Use case diagram for a Windows service application developed in C# 在monomac和xcode中开发的C#应用​​程序不能在具有单一框架的Windows上执行 - C# application developed in monomac & xcode not executing on windows with mono framework 在C#Windows窗体应用程序项目中更改自动生成的代码 - Changing autogenerated code in a C# Windows Forms Application project c# 是否可以在 windows 表单应用程序中显示实时网页? - c# is it possible to show a live webpage in a windows form application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM