views:

40

answers:

2

Hello,

I'm buidling an WPF application using the examples given in the link below as a basis:

http://www.robbagby.com/silverlight/patterns-based-silverlight-development-part-ii-repository-and-validation/

In the example given, the uses the OnValidating partial method to invoke validation and if nessesary, throw an exception when something is not valid.

In the ADO.NET EF, there is no partial method who can allow you to do this, e.g. There is no OnValidating method to override. What there is, are partial methods like: OnPropertyChanging and OnPropertyChanged, but i believe they will be executed immidiatly when you change a property which can given problems when using databinding (i dont have experience with WPF, but as far as i can remember from winforms, a grid for example will immidiatly construct an empty instance of the model and pass in the values afterwards. Therefore throwing an exception at the very beginning because some requirements have not met (is a property set for example).

So based on that, am i just looking in the wrong direction here? is there a better way to perform validation?

Thnx in advance!

+1  A: 

You should use ValidationRules in WPF. They are designed just for validation purposes.

Have a look here

Tony
A: 

You might be interested in the BookLibrary sample application of the WPF Application Framework (WAF). It shows how to use validation in WPF + Entity Framework and how to control the Save button when validation errors exists.

jbe