A user on the Blend/SketchFlow forums wanted to know if there was an easy way to add very basic validation for a form in a prototype. Below is a simple behavior that will validate that a text box is not empty, or if it matches a regex you provide, or both.

If you add this behavior code to your SL application in Blend, and change the namespace to match your project, and then build, this behavior will be available in the asset panel to drag out onto a TextBox. After you create it, you can select the behavior and edit its properties in the property panel. There you can set the regex that is validated, or set whether empty text is allowed.

using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace SilverlightApplication9
{
	using System.Text.RegularExpressions;

	public class SimpleValidationBehavior : Behavior<TextBox>
	{
		public static readonly DependencyProperty RegexStringProperty = DependencyProperty.Register("RegexString", typeof(string), typeof(SimpleValidationBehavior), new PropertyMetadata(string.Empty));

		public string RegexString
		{
			get { return GetValue(RegexStringProperty) as string; }
			set { SetValue(RegexStringProperty, value); }
		}

		public static readonly DependencyProperty CanBeEmptyProperty = DependencyProperty.Register("CanBeEmpty", typeof(bool), typeof(SimpleValidationBehavior), new PropertyMetadata(false));

		public bool CanBeEmpty
		{
			get { return (bool)GetValue(CanBeEmptyProperty); }
			set { SetValue(CanBeEmptyProperty, value); }
		}

		protected override void OnAttached()
		{
			base.OnAttached();

			var tb = this.AssociatedObject;
			if (tb != null)
			{
				tb.TextChanged += new TextChangedEventHandler(tb_TextChanged);
			}
			Validate();
		}

		protected override void OnDetaching()
		{
			base.OnDetaching();

			var tb = this.AssociatedObject;
			if (tb != null)
			{
				tb.TextChanged -= new TextChangedEventHandler(tb_TextChanged);
			}
		}
		void tb_TextChanged(object sender, TextChangedEventArgs e)
		{
			// Validate text.
			Validate();
		}

		private void Validate()
		{
			var tb = this.AssociatedObject;
			var text = tb.Text;

			bool emptyValid = this.CanBeEmpty ? true : !string.IsNullOrEmpty(text);
			bool regexValid = string.IsNullOrEmpty(this.RegexString) ? true : Regex.IsMatch(text, this.RegexString);

			bool valid = emptyValid && regexValid;

			if (valid)
			{
				VisualStateManager.GoToState(tb, "Valid", false);
			}
			else
			{
				if (tb.Focus())
				{
					VisualStateManager.GoToState(tb, "InvalidFocused", true);
				}
				else
				{
					VisualStateManager.GoToState(tb, "InvalidUnfocused", true);
				}
			}
		}
	}
}
<TextBox Height="38" Margin="138,78,314,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" >
			<i:Interaction.Behaviors>
				<local:SimpleValidationBehavior RegexString="[0-9][0-9][a-z]"/>
			</i:Interaction.Behaviors>
		</TextBox>