How to ease the transition from WinForms to 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 MV-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?


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.

    链接地址: http://www.djcxy.com/p/42786.html

    上一篇: 这是值得的努力

    下一篇: 如何简化从WinForms到WPF的转换