views:

215

answers:

1

Hi! I've created a WCF RIA Service that I'd like to use with a WPF application. I've added several System.ComponentModel.DataAnnotations validation rules on the entities meta-data, all which work great on the server when I call .SubmitChanges(changeSet) from the client. I'd also like to validate my entities on the client side before I sumbit my changes to the server but I have no idea how to do so. Any help in this regard would be greatly appreciated! Thanks....

A: 

As far as I know, there is no WCF RIA Services for WPF (although I'd be glad to be proven wrong, as I am waiting for this...), so you have to do the client-side work yourself.

Use the VisualTreeHelper to go over every control in your form, and recursively if the control is a panel. For each control, have a list of potentially-bound properties (I guess there is only one in this case). For example, a TextBox will potentially have its TextBoxProperty bound, a CheckBox will have its IsCheckedProperty bound. Use BindingOperation.GetBinding to get a Binding instance, which gives you the Source and Path properties. Now use reflection on the source to see if there is a data annotation associated with it. If there is, check it.

Yes, it is a lot of code.

Timores
Thanks for the quick answer! Unfortunately, my app doesn't use binding. I create one or more ChangeSetEntry by hand then send them across the wire by invoking SaveChanges(changeSet). I'd like to validate the data BEFORE it goes over the wire. Unfortunately, like you said, it appears the I'm S.O.L. Anyway, thanks again for your help...
lsb
I used Binding as a way to get at the source object and its members. From a ChangeSetEntry, you have access to the modified entity and its original values. Comparing them would give you the modified members and thus, through reflection, would give you the data annotations to check.
Timores