locked
Validating input in WinRT? RRS feed

  • Question

  • Hi.

    Since niether validation events nor IDataErrorInfo or similar seems to be existing in WinRT, what would be the best way to handle validation and present the user with information where he inputed the wrong value?

    My thinking was that using a converter i could set a property on the source control, but it doesnt seem there is a good way to access it from a converter.

    Saturday, March 24, 2012 11:50 AM

All replies

  • I think you're going to have to use brute force from the PropertyChanged event.

    Rebecca M. Riordan

    Sunday, March 25, 2012 3:27 PM
  • Hi.

    Since niether validation events nor IDataErrorInfo or similar seems to be existing in WinRT, what would be the best way to handle validation and present the user with information where he inputed the wrong value?

    My thinking was that using a converter i could set a property on the source control, but it doesnt seem there is a good way to access it from a converter.

    Even though IDataErrorInfo is not present, you can find INotifyDataErrorInfo which is newer version that supports asynchronous validation.

    However, it is not supported in WinRT as of Consumer Preview.

    Some validation investment should really be done.

    - ngm

    • Edited by ngmO11 Saturday, March 31, 2012 1:58 AM More clearly statement
    Saturday, March 31, 2012 1:53 AM
  • INotifyDataErrorInfo and DataAnnotations seem to be the ticket for WinRT moving forward.

    http://www.emileinarsson.se/silverlight-4-mvvm-validation-inotifydataerrorinfo/ looks like a good article which marries the two concepts nicely (Silverlight, but should apply to WinRT, give or take a little elbow grease.)

    Saturday, March 31, 2012 1:59 AM
  • Ah, guys...why are you recommending use of an api that isn't there? Do you know something that I don't? (Well, you certainly know lots of things that I don't, but I mean about the immediate future of WinRT, <g>)


    Rebecca M. Riordan

    Saturday, March 31, 2012 1:27 PM
  • It's in there - System.ComponentModel.INotifyDataErrorInfo as part of .NET Framework Core (.NET profile for metro) ;)

    - ngm

    Saturday, March 31, 2012 6:35 PM
  • It's in there - System.ComponentModel.INotifyDataErrorInfo as part of .NET Framework Core (.NET profile for metro) ;)

    - ngm

    Um....

    per David Kean (BCL team: "There is no DataAnnotations support in .NET for Metro style apps. Thanks for the suggestion, we'll keep it in mind as we plan future releases."

     (http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/c8590337-783c-4050-b130-5ee2820c86ba)

    per Tim Hueur (XAML Program Manager): "INDEI is not currently supported.  Validation like in Silverlight is not currently available."

      (http://social.msdn.microsoft.com/Forums/en-AU/winappswithcsharp/thread/1749b3e4-87f2-4617-af30-c7be91455b52)

    per Migrate/port from Phone docs: "There is no built-in support for data-entry validation and the IDataErrorInfo and INotifyDataErrorInfo interfaces."

      (http://msdn.microsoft.com/en-us/library/windows/apps/hh465136.aspx)

    and while a search for INotifyDataErrorInfo does return a search result, it's listed as 'not included in this library' and it's not listed under Systems.ComponentModel in the API docs.

    That said, my Win8 machine is dead (the joys of pre-release software) so I can't try referencing it in a project until I get it re-built. Docs and experts have been known to be wrong. Are you using it in a Metro app?


    Rebecca M. Riordan

    Saturday, March 31, 2012 9:07 PM
  • Rebecca,

    No, I'm not using it because it doesn't look usable to me ;) It's located in System.ObjectModel.dll from .NET Core but unfortunately it seems there's no dependency on it.

    First two posts dates pre-Consumer Preview and I can confirm that Developer Preview didn't include this interface. API documentation is subject to change as well.

    However, the migration paper doesn't promise that this will be included.

    - ngm

    Sunday, April 1, 2012 1:32 AM