If I understand you right you want to make sure the name of boats are all unique across the collection.
I have done tackled this sort of problem when it comes to "seasonal addresses". Someone can have a collection of addresses but the "month/date" ranges of seasonal addresses can't overlap.
Your case is much clearer so I'll just tell you how I'd tackle your problem.
I would first add a public get/internal set property on your boat named "IsBoatNameUnique". On a listchanged event of your collection, when a name is changed on a boat - or when boats are added or removed from the collection, you'd do a survey across the collection looking for name collisions. If you find collisions, the collection would communicate to their members via the internal set of the IsBoatNameUnique to tell whether or not the boat name is unique.
Then, on the boat, there would be a rule added - IsBoatNameValid, which would simply check this flag - if the name is not unique, broken rule, and the two "same named" boats would be invalid within the collection.
That is (at least if your problem is the same as my seasonal addresses entirely) how I'd probably tackle it. Though if anyone else has done this sort of thing differently I'd certainly be interested in hearing alternative solutions.
Thanks Andy, that makes good sense.
One nice thing to invalidating elements of the collection themselves is that if you have any number of them in a grid, you can highlight the "errant" ones and the databinding refresh is there, etc.
skagen00:One nice thing to invalidating elements of the collection themselves is that if you have any number of them in a grid, you can highlight the "errant" ones and the databinding refresh is there, etc.
IsValid doesn't encumber any extra processing. It just knows there are children that are now invalid. The only time checking needs to be done is when an item is added/removed or an item's property of name changes.
Copyright (c) Marimer LLC