Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restructure Win Forms application to MVVP pattern – possible future WPF version

I’ve recently started working on a Win Forms application which needs some improving and restructuring. There are chances that a WPF version of the application is done in the future and I’m considering restructuring the Win Forms app to the MVVM pattern. The purpose is that when the time comes to develop the WPF I would only have to focus on creating WPF views and reuse the code from the previous version.
I’ve looked at a few posts on developing a Win forms application using the MVVP pattern and it does seem possible to develop Win Forms application using the pattern.
I’d like to know if the approach is advisable and if restructuring an existing Win Forms application to a MVVM pattern would ease the work load when developing a WPF version.

like image 819
Rauland Avatar asked Nov 25 '11 11:11

Rauland


People also ask

Is WPF MVVM?

MVVM is the lingua franca of WPF developers because it is well suited to the WPF platform, and WPF was designed to make it easy to build applications using the MVVM pattern (amongst others).

Why MVVM WPF?

MVVM is a way of creating client applications that leverages core features of the WPF platform, allows for simple unit testing of application functionality, and helps developers and designers work together with less technical difficulties.


2 Answers

This is not a good idea in my mind. Because a really big part why MVVM is so good in WPF, is the WPF bindings infrastucture. WinForms doesn't have such abilities, binding support is way lower. That is why WinForms use MVP pattern, where Presenter is responsible for providing data to the view. You can try writing purely MVVM models, but then you'll have to write quite a lot of ugly code inside your views in order to bind to the models and update them. I would suggest stick to MVP, as this is quite a good aproach for WinForms, it creates well structured components, and then it is easy to recreate the same functionality in WPF and MVVM.

like image 110
Vladimir Perevalov Avatar answered Oct 11 '22 23:10

Vladimir Perevalov


As per other respondents the problem here is the presentation layer, which WinForms doesn't handle as easily as WPF.

That said, based on my experience, many legacy WinForm applications have a lot of business and data layer logic in the forms code.

I see no reason why you shouldn't ensure that the code is separated out into distinct data layer, business logic and GUI in preparation to a possible move to WPF.

like image 36
ChrisBD Avatar answered Oct 12 '22 00:10

ChrisBD