ValidationResult output to custom control

Jan 20, 2012 at 9:00 AM


I am totally new to Catel, so please apologize my poor knowledge. I have tried to find the answer in Documentation and in Discussions but with no results.

I am building WPF applivcation using Prism for navigation and MEF for modularity reasons. I wolud like to use Catel validation feature, but without integration into Catel proprietary controls. I am trying something like this:

public List<IValidationResult> FormValidationResult
                return this.ValidationContext.GetValidations();

and bind FormValidationResult in my XAML to ListView (or whatever else). However, this isn't working as the List object doesn't notify changes. So, as the Validate method adds the error (or warning) to the list, this change isn't reflected in UI. Is there any possibility to do this? I'd like to see some method returning ObservableCollection<IValidationResult> so the binded contrrol would refresh automatically. Could you help me, please?


Jan 20, 2012 at 9:15 AM

Hi Tomas, and welcome to the club :)

The ValidationContext is being filled by the ViewModelBase of Catel, but you say that the validation context is correctly being filled in your case as well?

The ValidationContext is a momentum, and most of the time validation contexts are merged together. What you can do is every time you run your validation sequence, is to call something like this:

RaisePropertyChanged(() => FormValidationResult);

If that doesn't fit your goals, please let us know how you see a better implementation.

Jan 20, 2012 at 10:04 AM

Hi Geert,

thank you for the quick response.

ValidationContest is filled correctly and I can access all of its members on demand. Here is the scenario:

I have form containing something like this:

<TextBox Text="{Binding Email, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
<Button Content="Submit" Command="{Binding SubmitForm}"/>
and submit button calls command:

SubmitForm = CommandHelper.CreateCommand(OnSubmitFormExecute, () => FormValidationSummary);


public IValidationSummary FormValidationSummary
                return this.ValidationContext.GetValidationSummary();

The Email property is implementing validation so it can not be empty. This works well, if I change focus from the TextBlock leaving it blank, its edge goes red. In addition, Submit button is disabled, so this works too. What I want is to kind of implement functionality of InfoBarMessageControl that the error appears immediatelz on focus change (ValidateModelInInicialization). Now, I can display errors ba manually raising event (as you have written) but I am looking for solution to do this autoamtically. Does Catel provide way to automaticaly notify the change in ValidationContext?

Jan 20, 2012 at 10:28 AM

There is a control that the InfoBarMessageControl uses internally. This is the WarningAndErrorValidator. What this thing does it subscribe to IDataErrorInfo on the source object and provide these errors in a genric way (a bit like the ValidationContext does). This is the actual source of the InfoBarMessageControl. Another thing you can do is simply customize the template for the InfoBarMessageControl and make it look like you want.

Jan 23, 2012 at 11:38 AM

Thank you, now it is clear.