views:

36

answers:

0

The background

Maybe it is not necessary, but I am afraid that single line question would be too complex.

So... I had min-max generic range validator (RangeValidator), because XAML does not work with generic classes I created simple derivative IntRangeValidator which would set int as generic type, because in current case I need validation for int values. It worked.

public class IntRangeValidator : RangeValidator<int>
{ 
} // that's really whole class, just for XAML

Then I wanted to databind the Min and Max properties, so I created nested (in RangeValidator class) class Range with min and max properties -- now dependency properties, and in the main class (RangeValidator) I changed min and max properties to one property (Values) of type Range. Please note, that Range is implicitly generic class too, because it is nested class within generic one.

IntRangeValidator did not change.

So far so good. And now XAML and generics strike again...

The question

How to set up those "new" Min and Max properties? Now they are dependency properties but also nested properties.

I have such code:

<Binding.ValidationRules>
  <app:IntRangeValidator>
    <app:IntRangeValidator.Range>
      <app:IntRangeValidator.Values Min="1" Max="100"/>
    </app:IntRangeValidator.Range>
  </app:IntRangeValidator>
</Binding.ValidationRules>

In sense of C# this should make sense, because IntRangeValidator inherits from RangeValidator, so the (sub)type Range and property Values is 100% available for it. XAML however does not like it:

  • The attachable property 'Range' was not found in type 'IntRangeValidator'.
  • The attachable property 'Values' was not found in type 'IntRangeValidator'.
  • The tag 'IntRangeValidator.Values' does not exist in XML namespace 'clr-namespace:MyApplication'.

    Thank you in advance for any hints, links, and so on :-).

Workaround

To get things working, I moved all the logic to C# code, so I have full control over it.