WPF - Validator does not fire when bound to businessList

WPF - Validator does not fire when bound to businessList

Old forum URL: forums.lhotka.net/forums/t/3397.aspx


Curelom posted on Friday, August 17, 2007

I have a form with a listbox containing a businesslist.  Below the listbox I have detailed information on the object selected where the user can edit.

So I have a CslaDataProvider

<csla:CslaDataProvider x:Key="ticketList"

ObjectType="{x:Type hd:TicketList}" FactoryMethod="GetUserActiveTicketList"

IsAsynchronous="True" ManageObjectLifetime="True" IsInitialLoadEnabled="False">

I have the listbox bound as such

ItemsSource="{Binding Source={StaticResource ticketList}}"

The DataContext of the Validator surrounding the detail information is set to {Binding Source={StaticResource ticketList}}

When I select different items from the listbox, the detail textboxes change data correctly, however when I enter data that would violate one of the business rules, the validator does not fire.

If I set the DataContext of the detail information to the Listbox {Binding ElementName=MyTicketList, Path=SelectedtItem} then the validator does fire correctly.  Is this a bug in the Validator or am I not understanding wpf correctly?

Also, Rocky, Is your next ebook going to contain strategies for sorting BusinessLists with wpf/xaml?

Thank you

 

RockfordLhotka replied on Sunday, August 19, 2007

Validator works against IDataErrorInfo, just like the ErrorProvider control in Windows Forms. This means its DataContext must be an IDataErrorInfo. Lists never implement this interface, because it has no meaning for collections, so you must wrap single objects with a Validator.

Typically, when dealing with a list, this means you put the Validator in the data template, so each item in the display ges its own Validator that monitors that particular child object's status.

Copyright (c) Marimer LLC