4

for some reason my program don't find my Custom Validation Rule für my TextBox. I define the namespace where my Validation Rule is located

xmlns:valRule="clr-namespace:MovieDB.UI.Validation"  

and i bind my rule to the TextBox

 <TextBox x:Name="textBoxName" Height="23" Margin="59,13,10,0" TextWrapping="Wrap" VerticalAlignment="Top">
        <TextBox.Text>
            <Binding Path="archiveName">
                <Binding.ValidationRules>
                    <valRule:ArchiveNameValidationRule />
                </Binding.ValidationRules>
            </Binding>
        </TextBox.Text>
    </TextBox>

I define my Rule here

namespace MovieDB.UI.Validation
{
    public class ArchiveNameValidationRule : ValidationRule
    {

        private static char[] FORBIDEN_CHARS = new char[] { '*', '&', '#', '/', ' ', '\\', '+', '=', '?', ')', '(', ']', '[', '}',
            '{', '%', '$', '§', '"', '!', 'ö', 'ü' ,'ä', 'Ä', 'Ö', 'Ü', ':', '.', ';', ',', };

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            String val = value as String;
            bool result = val.IndexOfAny(FORBIDEN_CHARS) != -1;
            ValidationResult vr = new ValidationResult(result, "Es sind nur Zahlen, Buchstaben und Unterstriche erlaubt.");
            return vr;
        }
    }
}

I'm always getting the error:

The tag ArchiveNameValidationRule does not exist in namespace 'clr-namespace:MovieDB.UI.Validation'.

even if i locate the rule in the same namespace as the Window i have no success.

UPDATE: If i change the the Target Framework my new validation rule is found after the project is reopend.

4

0 回答 0