Validating Data in ListBox in WPF

I have a ListBox associated with an ObservableCollection of type T - each ListBoxItem is a flag with IsChecked attached to the bool property in T. I want to check the checked items in the ListBox to mark at least one flag - if none of the checkboxes are checked, I want show a red frame (standard validation notification) around the ListBox.

How should I do it? Can I use ValidatesOnDataErrors?

+3
source share
1 answer

Inject it IDataErrorInfointo the class that provides the property ObservableCollection<T>and make the indexer return an error for this property name if all objects in the collection have a value falsein their logical property. Then use DataErrorValidationRulein your binding ValidationRules.

+2
source

Source: https://habr.com/ru/post/1780033/


All Articles