Hello,
Would greatly appreciate if someone can help me solve this issue, I apologize in advance if its a silly question. Thanks for the help.
I am trying to display an error if any object in a businesslistbase object is invalid. I thought I can simply use PropertyStatus but it disables the list box in UI. If I can't do this, is there another way I can do this?
Employee --- Business Base
child -> BankInfoList --- Business List Base
child --> BankInfo --- Business Base
WPF
<ListBox Name="Emp_BankInfoList_ListBox"
ItemsSource="{Binding BankInfoList}"
ItemTemplate="{StaticResource ListTemplate_BankingDetails}"/>
<csla:PropertyStatus Property="{Binding BankInfoList}"
TargetControl="{Binding ElementName=Emp_BankInfoList_ListBox}"/>
PropertyStatus won't do what you want.
Because you set its TargetControl property, you are telling PropertyStatus to enable/disable the UI control (your listbox). Since CanWriteProperty always returns false for a list (you can never alter properties of the list itself) PropertyStatus disables the UI control because it thinks the user isn't authorized.
But even if that was not happening, it still wouldn't work because the list itself has no errors. In fact, list objects don't implement IDataErrorInfo so they can't report errors.
The answer is to write a valueconverter or other bit of code that loops through all the items in the list, using IDataErrorInfo to get the errors from each item. Then consolidate those into an ObservableCollection<string> and bind that to something in your UI.
Hi Rocky,
Thank you for a quick reply. After without much success trying to implement valueconverter ( probably because I just don't know enough) I decided to try a different approach.
In BB (root parent) I created a IsChildListObjtValid property with simple custom validation rule and also did override OnChildChanged as follow:
{ base.OnChildChanged(e);
Type childObjectType = e.ChildObject.GetType();
if (childObjectType == typeof(Library.ChildListObjt) || childObjectType == typeof(Library.childObjt))
{
if (!ChildListObjt.IsValid)
IsChildListObjtValid = true;
IsChildListObjtValid = ChildListObjt.IsValid;
}
}
In WPF I simply used <csla:PropertyStatus Property="{Binding IsChildListObjtValid}"/>
This is probably not an effective way of just trying to show if list is valid or not but it works. I think I should probably implement what you suggested but I just couldn't figure how?
Thanks
Oh, I thought your list was the root object. Yes, if you have a BB root above the list, then your solution is the simplest and generally best approach.
Copyright (c) Marimer LLC