I’m trying to write a custom WPF ValidationRule to enforce that a certain property is unique within the context of a given collection. For example: I am editing a collection of custom objects bound to a ListView and I need to ensure that the Name property of each object in the collection is unique. Does anyone know how to do this?
I’m trying to write a custom WPF ValidationRule to enforce that a certain property
Share
First, I’d create a simple DependencyObject class to hold your collection:
Then, on your ValidationRule-derived class, create a property:
Then, in the XAML, do this:
Then in your validation, look at ListToCheck’s BoundList property’s collection for the item that you’re validating against. If it’s in there, obviously return a false validation result. If it’s not, return true.