views:

63

answers:

1

First i'm not mad, because i use MVVM in WinForms-) I know about MVP (Model View Presenter) pattern and it's variants. But when i started this project i was going to learn WPF and use it, but i'm forced to rush program development, and have no time to learn WPF, so i have to write it in WinForms which i know well.

So in short i have a large data oriented smart client application, which is close to finish, i have all Models and ViewModels done (Infrastructure, Domain, Presentation done) UI is done too, now i only need to wire UI to ViewModels. First i started wiring it using standard winforms way (BindingSources, and simple databinding) but when i did 30-50% of binding i found out that my program works very slow, i have like 100-150 bound properties total so far, 30 of them are domain root entity (aggregate root) bindings to it's EditForm. So databinding doesn't work well in this situation, lots of unnecessary updates, cascade updates of entire view when something small changes, unclear behavior, and other ugly stuff. It smells like very unreliable code, on which i have little control. So i began to rewrite wiring as pure clean WinForms code (subscribing to PropertyChange and ListChanged events, and setting ViewModels property on my own from UI). Lot's of code to write but it works much faster, i have full control on this, and it feels much more reliable. So what's your thoughts on this guys? Anyone had such experience? What's your verdict on "To DataBind or Not"?

+3  A: 

You might want to take a look at Truss. It provides a WPF-style binding manager that works on POCOs. It makes using MVVM with Windows Forms much more effective.

Reed Copsey
Very interesting, it's almost the solution i made for myself, i have wrote UI agnostic small databinder manager myselfm with some reflection stuff but it works only on INotifyPropertyChanged objects so i had to subclass WinForms controls and override the properties i need, i was going to make some AOP style code injection in property setters using Spring Framework, but i failed in this not enough time,skill. Do they use some kind of code injection in setters?
Broken Pipe
No - they work directly on POCO's that implement INPC. It's pretty slick.
Reed Copsey
Nice one, looked at their SRC, same thing i did, my and their sources are pretty close, and usage is same, i guess hard to implement this other way :-) But as in my case this binding works just on INPC objects, so to bind it to for example ComboBox.SelectedItem I will have to do MyCombobox : INPC {object SelectedItem {set {base.SelectedItem = value; OnpropertyChanged} and unfortunately even this way it doesn't work well, lots of event fire stuff\propety set bugs in WinForms controls, i will have to rewrite them (i tried this too, lots of work, did some.)
Broken Pipe
It would be much nicer to have some interception stuff in property SET method like it is in Nhibernate for example.
Broken Pipe
Interesting thing i found "remade" WinForms controls in http://updatecontrols.codeplex.com/ project, they subclass WinForms controls and add OnGet OnSet handlers in control properties, pity they don't just add OnPropertyChanged stuff there. I could rewrite their subclassed controls with INPC to use with Truss.
Broken Pipe