views:

32

answers:

0

Suppose you have a class inheriting from ValidationRule:

public class MyValidationRule : ValidationRule
{
    public string ValidationType { get; set; }

    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {}
}

in XAML you are validating like this:

<ComboBox.SelectedItem>
    <Binding Path="MyPath" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" NotifyOnValidationError="True">
        <Binding.ValidationRules>
            <qmvalidation:MyValidationRule  ValidationType="notnull"/>
        </Binding.ValidationRules>
    </Binding>
</ComboBox.SelectedItem>

Which works and everything is ok.

But suppose now, you want to have ValidationType="{Binding MyBinding}" where MyBinding comes from DataContext.

For this purpose I would need to make MyValidationRule as a DependencyObject and add a Dependency Property.

I've tried to write a class that is DependencyObject, and bind it. There are 2 problems though.. the ValidationRule DOES NOT have the DataContext from the Combobox / Item.

Do you have any idea, how to solve that?

Thank you !