WPF ValidationRule Binding is throwing XMLParseException
I have the following ValidationRule class in WPF
public class EmptyFieldValidationRule: BaseValidationRule
{
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
var fieldValue = (string)value;
if (fieldValue.Trim().Length == 0)
{
return new ValidationResult(false, "Field Is Empty");
}
else
开发者_运维百科 {
return new ValidationResult(true, null);
}
}
}
NOTE - BaseValidationRule extends the normal ValidationRule class.
This is really just a test validation class because I wanted to start off easier.
I am attempting to bind this to a textbox in my XAML, and it is reading in the BaseValidationRule class fine, it is even giving me it in Intellisense, but when I go to run the program and it hits that part of the application, it tells me an XMLParseException.
I am defining an ErrorMessage property in the XAML, which is inherited in the EmptyFieldValidationRule class from the BaseValidationRule.
The XAML for the ValidationRule Binding looks like the following
The Error Message I am getting is the following.
XAMLParseException occured, Could not load file or assembly XXX.ValidationRule, Public KeyToken = null, or one of its dependencies. The system cannot find the file specified.
I have made the reference available to the ValidationRule assembly, and the intellisense is reading in the ValidationRule fine in my XAML, is there something else I need to do?
Please, make sure you have a XML namespace defined in your XAML document as follows:
xmlns:validation="clr-namespace:Some.Assembly.Name.Some.Namespace.Containing.Validations;assembly=Some.Assembly.Name"
Where Some.Assembly.Name.Some.Namespace.Containing.Validations should be your namespace full name containg EmptyFieldValidationRule
class, and Some.Assembly.Name should be library name for that class.
Is the reference to the validation assembly in the project with the XAML set to "Copy Local = True" ? If not, this would explain the issue.
精彩评论