I have ObservableCollection and ItemsControl
public ObservableCollection<SomeData> Datas { get; }
I`am trying to validate a duplicate exists.
<ItemsControl ItemsSource="{Binding Datas}">
<!-- ... -->
</ItemsControl"
I wrote I simple example (I'm not sure if that works but also it needs a Proxy):
public class CollectionUniqueValueValidationRule : ValidationRule
{
public IList ExternalList { get; set; }
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
var knownKeys = new HashSet<dynamic>();
for (var i = 0; i < ExternalList.Count; ++i)
{
if (!knownKeys.Add(ExternalList[i]))
{
return new ValidationResult(false, "Already exists");
}
}
return ValidationResult.ValidResult;
}
}
But if it works, it just shows me one problematic item:

But I need result as the first image.

Ok, I wrote a simple example. NOTE: this is a bad realization, I do not advise to use it.
The main idea was that we can check not only the objects, but also the individual property of them. For this I created a separate property
ValidatingPropertyName.Disadvantages of implementation
Code demo
How to use
I wrote property name which I will validated at the future. If you do not specify this property, the program will not search for any properties inside the object, but will compare the objects themselves with each other. There was also an idea to add the ability to search properties more deeply like that:
SomeProperty.SomeAnotherPeoprty.Surname. But I didn't.