如何将WPF代码重写为winform [英] How do I rewrite the WPF code to winform

查看:458
本文介绍了如何将WPF代码重写为winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个小项目,我希望将应用程序与我的WiFi灯泡连接起来。

我已经拥有原始Windows应用程序的源文件,但它是用WPF制作的。

我想把它变成一个WinForm应用程序,因为它使得构建和开发更容易,因为我对WPF不太好。





问题是即使我有源代码在我面前,

也很混乱。我以为它只是复制/粘贴它(听起来很懒但我在WinForm中需要相同的功能)

但事实证明它并非那么简单。



正如您在下面的GitHub链接中看到的,一切都在那里。

https://github.com/dotMorten/LifxNet/tree/master/src/SampleApps/SampleApp .Windows



1.它找到连接的灯泡

2.能够打开和关闭它。



出于某种原因,很难找到哪个以及如何将其转换为WinForm状态而不是WPF。



我需要帮助的确是。



1.什么使应用程序能够找到灯泡,我如何在一个灯泡中找到相同的东西WinForm应用程序。 (因为它显然与WPF的代码不同)

2.控制灯开关的功能(开/关)



任何帮助都很高兴!



我尝试过:



我试过阅读代码(WPF应用程序)并试图在WinForm中重新创建它,我现在也用Google搜索了大约2天而没有成功。

So I am working on a small project where I want to connect a application with my WiFi lightbulb.
I already have the source files for the original Windows application but its made with WPF.
I would like to make it into a WinForm application because it makes things alot easier to build and develop since im not too good with WPF.


The issue is that even though I have the source code infront of me,
its very confusing. I thought it would be just copy/pasting it(Sounds lazy but I needed the same functionallity in a WinForm)
but it turns out that it wasnt that simple.

As you can see in the GitHub link below, everything is there.
https://github.com/dotMorten/LifxNet/tree/master/src/SampleApps/SampleApp.Windows

1. It find the connected lightbulb(s)
2. Its able to turn it on and off.

For some reason it was really hard to find which did which and how to convert it into a WinForm state and not a WPF.

What I need help with exactly is.

1. What makes the application able to find the lightbulb and how do I achieve the same thing in a WinForm application. (Since its apparently not the same code as a WPF)
2. Which function is it that controls the light switch (On/Off )

Any help is highly appriciated!

What I have tried:

I've tried reading through the code (the WPF application) and tried to recreate it in WinForm, I've also googled for about 2 days now and no success.

推荐答案

基本上,不要:两个系统真的不够接近,不能尝试使用相同的代码,甚至尝试找到类似的控件。

相反,使用调试器运行WPF应用程序,找到完成工作的代码,通过逐步执行并使用断点来计算出正在做什么。



然后考虑复制处理光线的非UI方法 - 甚至是整个类,如果编写得很好 - 并编写自己的UI来与它进行交互。



但是特定于WPF代码w在这里对你没什么用处。
Basically, don't: the two systems really aren't close enough to try and use the same code, or even to try and find "similar" controls.
Instead, use the debugger to run the WPF app, and find the code that does the work, by stepping through and using breakpoints to work out what is doing what.

Then consider copying the non-UI methods that deal with the light - or even the whole class if it's well written - and write your own UI to interface with it.

But the WPF specific code won't be much use to you here.


显然,你需要理解代码来转换它。因此,如果你不理解它,将WPF应用程序转换为WinForms没有任何意义。



因此,如果你不理解WPF代码,那么唯一剩下的选择是从一个空白的WinForms应用程序开始,并将所有必需的功能添加到WinForms应用程序。



但是,因为WPF比WinForms强大得多,你必须确保你可以在WinForms中实现你想要的一切。



但是如果是WPF应用程序,那你为什么要转换呢?如果没有破坏,那么就不要修理它。



鉴于WPF的能力远远优于WPF,并且还应该支持更容易的Hi-DPI设备和一些其他现代功能,将WPF代码转换为WinForms几乎没有意义。



即使你想将应用程序转换为WinForms,你需要学习WPF到能够了解现有的热门代码。假设这个代码可以移植到WinForms,一旦你理解了WPF就没有意义了,因为你可以直接对WPF应用程序做任何必要的调整。



WPF远远优于WinForms,因为它有助于将UI与逻辑分离,因此可以让一个UI设计器不需要进行太多的编程设计(在Blend中),并让一个程序员执行没有做UI的UI模型。这非常好,因为UI与代码的联系更少,因此在不修改代码的情况下更容易更改UI。



WPF也是优越的,因为它允许动画,转换以及更多应用于UI ...



关于您的代码

这里我们不做其他工作......因此,如果您有特定问题,请显示您想要转换的特定代码。这里没有人会转换整个应用程序。



如前所述,将WPF转换为WinForms的整个想法毫无意义。通常,从WinForms转换为WPF会更容易,因为理论上可以编写基于事件的WPF应用程序。但是,当你放弃UI和模型分离的所有好处时,这没有多大意义......
Obviously, you need to understand code to convert it. Thus it does not make any sense to convert a WPF application to WinForms if you don't understand it.

Thus given that you don't understand WPF code, then the only remaining option would be to start from a blank WinForms application and add all required functionality to the WinForms application.

But then since WPF is much more powerful that WinForms, you have to ensure that you could implement everything you want in WinForms.

But if the WPF application, then why you would convert it? If something in not broken, then don't fix it.

Given than WPF is far superior in its abilities and should also support more easily Hi-DPI devices and some other modern features, it would almost never make sense to convert WPF code to WinForms.

Even if you want to convert the application to WinForms, you need to learn WPF to be able to know hot existing code works. Assuming that this code can be ported to WinForms, it would make no sense to do so once you understand WPF as you might at that point make any necessary adjustment directly to the WPF application.

WPF is far superior to WinForms because it help separate the UI from the logic so that it is possible to have one UI designer that don't do much programmation to design (in Blend) and to have a programmer that do the UI model without doing the UI. This is really nice as the UI is much more less tie to the code so it is easier to change the UI without modifying code.

WPF is also superior because it allows animation, transformation and more to be applied to the UI...

About your code
Here we don't do other work... As such, if you have a specific question, then show specific code that you would like to convert. Nobody here would convert a whole application for nothing.

And as already explained, the whole idea to convert WPF to WinForms make little sense. Usually, it would be much easier to convert from WinForms to WPF as one could in theory write an event-based WPF application. However, this make little sense as you loose all the benefit of UI and model separation...


这篇关于如何将WPF代码重写为winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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