31 lines
881 B
C#
31 lines
881 B
C#
|
|
using System;
|
|||
|
|
using System.Windows;
|
|||
|
|
using System.Windows.Data;
|
|||
|
|
|
|||
|
|
namespace ValidationLibrary
|
|||
|
|
{
|
|||
|
|
public class ValidationBinding : BindingDecoratorBase
|
|||
|
|
{
|
|||
|
|
public ValidationBinding() {}
|
|||
|
|
|
|||
|
|
public ValidationBinding(PropertyPath path, UpdateSourceTrigger trigger, IValueConverter converter)
|
|||
|
|
{
|
|||
|
|
Path = path;
|
|||
|
|
UpdateSourceTrigger = trigger;
|
|||
|
|
Converter = converter;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override object ProvideValue(IServiceProvider pProvider)
|
|||
|
|
{
|
|||
|
|
base.NotifyOnValidationError = true;
|
|||
|
|
var lValidator = new AttributeValidator();
|
|||
|
|
base.ValidationRules.Add(lValidator);
|
|||
|
|
|
|||
|
|
object lResult = base.ProvideValue(pProvider);
|
|||
|
|
|
|||
|
|
lValidator.ExpressionToValidate = lResult as BindingExpression;
|
|||
|
|
|
|||
|
|
return lResult;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|