locked
How to Employ Validation in a Windows 8.1 Store App

    Question

  • According to the AdventureWorks sample application, I can achieve validation through the ValidatableBindableBase class and through code like this

    <TextBox x:Name="MyTextBox" AcceptsReturn="False" TextWrapping="NoWrap" Width="66"
                                                         PlaceholderText="Enter a value."
                                                         Text="{Binding TheBindingObject.TheBindingProperty, Mode=TwoWay}">
                                                <interactivity:Interaction.Behaviors>
                                                    <behaviors:HighlightFormFieldOnErrors PropertyErrors="{Binding TheBindingObject.GetErrors[TheBindingProperty]}" />
                                                </interactivity:Interaction.Behaviors>
                                            </TextBox>

    However, this does not highlight a textbox if something incorrect was entered into the textbox, nor does any accompanying code prevent the related form from being submitted. How then is validation supposed to be wiring up in a Windows 8.1 store app?

    Wednesday, November 19, 2014 5:55 AM

Answers

  • The trick is to use the HighlightFormFieldOnErrors, BindableValidator, ValidatableBindableBase and IValidatableBindableBase from the StoreApps library -- not from the AdventureWorksShopper example. Note: this applies to Windows 8.1 Store apps.
    • Marked as answer by IMOsiris Saturday, November 22, 2014 10:54 PM
    Saturday, November 22, 2014 10:54 PM

All replies

  • Validation is something that isnt coming out of the box with WinRT. So i assume your using the prism framework .

    In Prism framework GetErrors should be Errors[TheBindingProperty]. so for example:

    "{Binding Address.Errors[FirstName]}"

    It's the dictioniary where the errors come from. Bindings cant invoke a method


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#


    Wednesday, November 19, 2014 7:47 AM
  • I should have provided an example using Errors instead. However, Errors did not cause the field to be highlighted or for any visual cue to arise. I am using Prism, but is there more to making this simple case of validation work than just a single statement?
    Wednesday, November 19, 2014 4:29 PM
  • The trick is to use the HighlightFormFieldOnErrors, BindableValidator, ValidatableBindableBase and IValidatableBindableBase from the StoreApps library -- not from the AdventureWorksShopper example. Note: this applies to Windows 8.1 Store apps.
    • Marked as answer by IMOsiris Saturday, November 22, 2014 10:54 PM
    Saturday, November 22, 2014 10:54 PM