Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ease the transition from WinForms to WPF

Tags:

c#

.net

mvvm

wpf

I'm working on a large Winforms application dealing with large amounts of data exposed through grids. I see us eventually moving completely to an M-V-VM & WPF implementation but now we're still closer to a ball-of-mud than anything resembling loose coupling.

As we evolve toward cleaner separation of concerns, what are some specific patterns we can implement while still in the WinForms world but yielding a smoother transition once we take the WPF plunge? Specifically, is there any guidance on exploiting WinForms limited binding and event handling in a fashion that approximates WPF/MVVM?

like image 680
Douglas Avatar asked Jul 04 '09 05:07

Douglas


1 Answers

Recommending you to install Prism, and have a look at the samples.

http://www.codeplex.com/CompositeWPF

I suggest you to go ahead with a complete WPF approach. Few suggestions if you've a winforms background, when you come to WPF

  • 1 - Stick to MVVM
  • 2 - Instead of writing too much event handlers for controls, bind them to Commands (ICommand implementations)
  • 3 - Never ever try to deal with controls directly, for data related operations. Like trying to add a record directly to a listbox
  • 4 - In your View Model, make sure you are exposing collections for binding Treeview, Listview etc, and perform data operations (adding items, removing etc) on top of your collections.
  • 5 - Use background worker when ever possible (like for operations like loading data over a service).

And, finally, read this article on code project http://www.codeproject.com/KB/WPF/winforms2wpf.aspx "Creating the Same Program in Windows Forms and WPF" by Josh Smith.

like image 64
amazedsaint Avatar answered Oct 05 '22 10:10

amazedsaint