views:

42

answers:

1

Hi all,

I'm developing a WPF GUI framework and have had bad experiences with two way binding and lots of un-needed events being fire(mainly in Flex) so I have gone down the route of having bindings (string that represent object paths) in my controls. When a view is requested to be displayed the controller loads the view, and gets the needed entities (using the bindings) from the DB and populates the controls with the correct values. This has a number of advantages i.e. lazy loading, default undo behaviour etc. When the data in the view needs to be saved the view is passed back to the controller again which basically does the reserve i.e. re-populates the entities from the view if values have changed.

However, I have run into problems when I try and validate the components. Each entity has attributes on its properties that define validation rules which the controller can access easily and validate the data from the view against it. The actual validation of data is fine. The problem comes when I want the GUI control to display error validation information. It I try changing the style I get errors saying styles cannot be changed once in use. Is the a way in c# to fire off the normal WPF validation mechanism and just proved it with the validaiton errors the controller has found?

Thanks in advance

Jon

+2  A: 

Two things:

1) Trust the data binding in WPF. WPF's data binding is incredibly robust and very useful - there's no reason to let your "bad experiences" with other frameworks deter you from using the DataBinding. It will dramatically simplify your code.

2) The best option for data validation is to use WPF's built-in data validation capabilities. If you make your Data Context implementation (where the data is held for binding) implement IDataErrorInfo, you'll get the appropriate validation styles nearly for free (and completely customizable). This is the proper way to handle data validation on the UI in WPF.

Reed Copsey
great thanks for this, but is there a way to programatically implement validation or change styles?
Jon