Reputation: 1986
I am developing my wpf application and using INotifyDataErrorInfo for validation. I have two classes (A & B) and one of them (A) has two instances of the other one (B). Now I want to validation the property of B from A. Is that possible using INotifyDataErrorInfo?
Here's my sample code:
class BaseValidation : INotifyDataErrorInfo, INotifyPropertyChanged
{
// the implementaion of interface
public void MyValidationMethod(string propertyName, Func<bool> expression, string errorMessage)
{
}
}
class B : BaseValidation
{
public string MyString
{
get {return _myString;}
set {_myString = value;}
}
}
class A : BaseValidation
{
public B objB1;
public B objB2
A(){
objB1 = new B();
objB1.PropertyChanged += OnObjBPropertyChanged;
objB2 = new B();
}
private void OnObjBPropertyChanged(object sender, PropertyChangedEventArgs arg)
{
MyValidationMethod("objB1.MyString ", () => objB1.MyString != objB2.MyString , "Error");
// here validation will pass if MyString are not equal
}
}
I feel like I'm passing the wrong property name in the validation method. And I cannot implement this validation inside B
since I need the data of other B
object. I would assume this type of validation is possible, as I can assume this to be a common scenario, how can I do this?
Upvotes: 0
Views: 414