Oleg  Ignatov
Oleg Ignatov

Reputation: 865

Data validation of all elements in wpf

I have a window in WPF. I need to have a validation mechanizm to check all elements at once. If I use IDataErrorInfo there is only ability to validate one object at once in the indexer.

public string this[string columnName]
{
    get
    {
        if (columnName == "Country"))
        {
            if (string.IsNullOrEmpty(Country))
                return "Country can't be empty";
        }
        return null;
    }
}

How can I get all fields of my Window in the validation method?

Upvotes: 0

Views: 68

Answers (1)

Avram Tudor
Avram Tudor

Reputation: 1526

I think the best way is to declare a custom attribute and decorate the properties you wanna validate with it, and then use Reflection to iterate through those properties based on whether they have that custom attribute.

Upvotes: 1

Related Questions