This project is read-only.

How to use PatternErrorMessage

Jan 8, 2014 at 8:10 PM
Edited Jan 8, 2014 at 8:56 PM
I am wondering if anyone could offer a tip about how to use PatternErrorMesage.

I have the following code which works.
<TextBox x:Name="tbEmail" Width="400" Margin="10 0"
    WinRTXAMLToolkitExtensions:FieldValidationExtensions.PatternErrorMessage="Invalid email address."/>
However I do not know what is the best way to utilize PatternErrorMessage. Can it be linked to TextBlock to display it?

Jan 8, 2014 at 9:50 PM
Edited Jan 8, 2014 at 9:51 PM
Yes, if you look at the sample here - - you can see that there are TextBlocks with Text being bound to ValidationMessage properties of the input boxes. PatternErrorMessage defines what the message should be if the pattern is not matched. ValidationMessage is the first error that was found if one was found and ValidationMessageVisibility specifies whether the error UI should be visible.
    Style="{StaticResource ValidationErrorLabelStyle}"
    Text="{Binding (extensions:FieldValidationExtensions.ValidationMessage), ElementName=NonEmptyTextBox}"
    Visibility="{Binding (extensions:FieldValidationExtensions.ValidationMessageVisibility), ElementName=NonEmptyTextBox}"/>
Jan 9, 2014 at 1:07 AM
Thank you. This helps a lot. The samples are really helpful. I should spend more time on them. I did not know that the source code has so many samples.

Jan 9, 2014 at 1:11 AM
I forgot to mention that I have been using the following code and it has been fine.
if (WinRTXamlToolkit.Controls.Extensions.FieldValidationExtensions.GetIsValid(tbEmail))
    //code to accept the input
   // code reject the input
Apparently binding a TextBlock to the message is a much better way.