using System;
using System.Windows.Data;

using BeWo.Core;

namespace BeWo.Validation
{
    public class ValidationBinding : BindingDecoratorBase
    {
        public ValidationBinding() {}

        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;
        }
    }
}