开发者

Hook ValidationSummary onto a child of my ViewModel in Silverlight 4

I'm a bit at a loss about Silverlight Validation. I finally figured out how to use IDataErrorInfo together with INotifyDataErrorInfo so the red borders around Controls start showing up once I validate.

But for some weird reason I can't get the ValidationSummary to show up.

I am currently suspecting this has something to do with all my controls being bound to a child of the current ViewModel.

So the UserControl is bound to a NewCustomerViewModel while all the input elements are bound to a Customer object contained inside NewCustomerViewModel through bindings like t开发者_如何学Gohis:

<TextBox Text="{Binding Path=NewCustomer.Address, Mode=TwoWay, 
       ValidatesOnNotifyDataErrors=True, ValidatesOnDataErrors=True}"/>

I tried setting the ValidationSummary's DataContext property to Bind to the Customer Property, but that doesn't work out.

Any ideas?


I think it may be that you have to set the ValidationSummary's target property to a UI element. That is what did it for me.


Why are you implementing both the IDataErrorInfo and the INotifyDataErrorInfo interfaces? Although you can implement both, there's no need to. The INotifyDataErrorInfo interface is unique to Silverlight, and is better than the IDataErrorInfo interface (IMO). You don't need to set ValidatesOnDataErrors to True in your bindings then (since you don't use the associated interface), and you don't actually need to set the ValidatesOnNotifyDataErrors property to True either, as True is its default value.

However, this doesn't actually answer your question :). I'd probably need some more details (your XAML mainly) to give you more help. Any chance of putting together a sample project demonstrating the issue?

Chris

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜