A pretty common example of what I am trying to do is an invoice with invoice items.
Invoice aggregates a collection of InvoiceItem objects.
If I understand, if I were to add a ValidationRule it would be on the property InvoiceItems, but this property is readonly obviously so PropertyChanged is never going to be called on this property.
Obviously I can just put a check in the UI code when the person clicks the save button, but I am betting there is another way to tap into the validation checking or the IsValid method on the business objects to make sure that a InvoiceItem collection of length 0 is invalid.
You can always have the root Invoice object listen for the ListChanged event of the InvoiceItem collection and re-raise a PropertyChanged event.
Something like...
InvoiceItems.ListChanged += new System.ComponentModel.ListChangedEventHandler(ItemsChanged);
private void ItemsChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
{
PropertyHasChanged("InvoiceItems");
}
private static bool InvoiceItemsRequired(object target, RuleArgs e)
{
Invoice obj = target as Invoice;
e.Description = "At least one item must be on file!";
return (obj.InvoiceItems.Count > 0);
}
As long as you setup the validation rule to fire on "InvoiceItems", everything should work well...
Can you tell where you have to write this 2 methods in Invoice class or InvoiceItems class.
Can you provide them in VB.NET
never mind. I got answer.
I defined my list member with events and handling ListChanged in parent
Thanks
Soumya
Copyright (c) Marimer LLC