Share via


Validation Application Block, meet WPF

One of the few features we needed to cut from Enterprise Library 3.0 was a Windows Presentation Foundation "integration adapter" for the Validation Application Block. This was a tough call, and wasn't made because we didn't think it was an important scenario - rather it was because we were extremely pressed for time and didn't have enough WPF experience on the team for us to accurately predict how long it would take to implement a solid solution. Still we did do enough prototyping to ensure that it would be possible to build such an adapter, with the expectation that we, or someone else, would do so in the future.

Now I'm pleased to announce that that "someone else" has materialized in the form of Martin Bennedik - he has just written and published his WPF Integration Adpater for the Validation Application Block. Conceptually this works much the same way as the Windows Forms and ASP.NET Integration Adapters, in that it lets you bind UI controls with specific types and properties, and automatically validate the data in the controls using the validation rules specified on the types using attributes or configuration. Martin's provider integrates with WPF by providing a EnterpriseValidationRule class, which hooks into the WPF validation machinery, and an ErrorProvider class is able to extend controls to trigger the validation and display errors.

If you are using or experimenting with WPF, this is a great addition to the Validation Application Block. Please stop by Martin's blog to thank him for his contribution and provide him any feedback on the use of this extension.

Comments

  • Anonymous
    April 24, 2007
    Tom Hollander has a post about the Enterprise Library 3.0 being extended by the community. In this case,

  • Anonymous
    April 26, 2007
    hmm i notice he modifies paul stovell's error provider (which iterated through every single child element of the error provider each time data binding updated to the source). I found the performance on Stovell's error provider to be rather slow when many child elements existed under the error provider (10-20 elements) and went back to using implementations of IValidationRule. The biggest problem was doing UpdateSourceTrigger="PropertyChanged" of course, but the other Triggers were quite a bit slower as well.

  • Anonymous
    April 26, 2007
    Hi James, you can use the EnterpriseValidationRule directly, if the ErrorProvider is too slow for you. Use of the ErrorProvider is optional. Sincerely, yours Martin Bennedik

  • Anonymous
    April 28, 2007
    Better late than never... I have combined the last 3 weeks. In the pipeline: So much is in the pipeline

  • Anonymous
    April 30, 2007
    Martin, thanks for the reply! I"m going to start working on it today and see if i can just lessen the amount of validation happening per error provider. I think it was 'my bad' on the performance for starting at the top level of the tree! :) (we are using pentium3 666mhz-1ghz machines though so i have to be careful) also i think i if i split my tree up a bit more i can cut it down more. I downloaded your code and noticed the business entites weren't included with the samples... i was wondering if you could post those? i created them manually but i didn't know what i should put in the attributes for validation! (so it says my data is valid no matter what hah)

  • Anonymous
    May 22, 2007
    Is is possible to programatically retireve the values of the lowerbound & upperbound values of the StringLengthValidator? We are currently trying to create Unit Test classes for our classes that use VAB on several properties to automate the testing for the entire class. We are able to identify all VAB attributes that have been applied to each attribute, but when locating the StringLengthValidatorAttribute value I cannot programatically retrieve the upper/lower bound that was set on the property. It shows up in the watch window as non-public (hidden), so I'm guessing that we can somehow extract it through code. Anyone know of a way to do this?

  • Anonymous
    May 08, 2008
    As I mentioned here, I have been digging into what's out there for WPF LOB applications.  It's been

  • Anonymous
    May 08, 2008
    As I mentioned here , I have been digging into what's out there for WPF LOB applications.  It's