* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
2.0 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| How to: Implement Validation Logic on Custom Objects | 08/02/2018 |
|
|
751fda9b-44f9-4d63-b4f2-1df07ac41e0f |
How to: Implement Validation Logic on Custom Objects
This example shows how to implement validation logic on a custom object and then bind to it.
Example
You can provide validation logic on the business layer if your source object implements xref:System.ComponentModel.IDataErrorInfo, as in the following example, which defines a Person object that implements xref:System.ComponentModel.IDataErrorInfo:
[!code-csharpBusinessLayerValidation#IDataErrorInfo] [!code-vbBusinessLayerValidation#IDataErrorInfo]
In the following example, the text property of the text box binds to the Person.Age property, which has been made available for binding through a resource declaration that is given the x:Key data. The xref:System.Windows.Controls.DataErrorValidationRule checks for the validation errors raised by the xref:System.ComponentModel.IDataErrorInfo implementation.
[!code-xamlBusinessLayerValidation#BoundTextBox]
Alternatively, instead of using the xref:System.Windows.Controls.DataErrorValidationRule, you can set the xref:System.Windows.Data.Binding.ValidatesOnDataErrors%2A property to true.