Search code examples
c#silverlightidataerrorinfo

How do I validate my entities on pressing save button through IDataErrorInfo?


I have implemented IDataErrorInfo interface to validate my entities.

<TextBox Text="{Binding User.Name, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}" />

It works fine but I want to re-validate the data when the user presses the save button. Is their any way that exists to achieve this functionality in IDataErrorInfo.


Solution

  • Maybe you should consider using INotifyDataErrorInfo Interface

    this should give you more control... including a GetErrors method and more which you could execute on the button click command (I asume you are using MVVM)

    find Infos here:

    http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx

    and a good blog post here:

    http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/11/18/silverlight-4-rough-notes-binding-with-inotifydataerrorinfo.aspx