Home > Uncategorized > Validation in Windows phone, flash textbox red if invalid =WP8

Validation in Windows phone, flash textbox red if invalid =WP8

Here’s some nice code to flash a textbox red if the input is invalid – It’s tested in WP8.1

private void Warn(Control target)
{
var elementColour = ((SolidColorBrush)target.Background).Color;
ColorAnimation ca1 = new ColorAnimation();
ca1.Duration = new Duration(TimeSpan.FromSeconds(0.5));
ca1.From = elementColour;
ca1.To = Color.FromArgb(255, 255, 0, 0);
Storyboard.SetTarget(ca1, target);
Storyboard.SetTargetProperty(ca1, new PropertyPath(“UIElement.Background.Color”));
// alternative tested PropertyPath
// “Panel.Background.Color”
// “Panel.Background.SolidColorBrush.Color”
// “(Panel.Background).(SolidColorBrush.Color)”
Storyboard sb = new Storyboard();
sb.Children.Add(ca1);
sb.Begin();
sb.Completed += (a, b) =>
{
ColorAnimation ca2 = new ColorAnimation();
ca2.BeginTime = TimeSpan.FromSeconds(1);
ca2.Duration = new Duration(TimeSpan.FromSeconds(0.5));
ca2.From = Color.FromArgb(255, 255, 0, 0);
ca2.To = elementColour;
Storyboard.SetTarget(ca2, target);
Storyboard.SetTargetProperty(ca2, new PropertyPath(“UIElement.Background.Color”));
Storyboard sb2 = new Storyboard();
sb2.Children.Add(ca2);
sb2.Begin();
};
}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: