How have you decided to handle data/control validation in your silverlight applications?
You can throw and capture data validation exceptions.
To manage both of these types of errors need to take 3 steps:
Taken from here.
Sample code:
// page.xaml.cs
private bool clean = true;
private void LayoutRoot_BindingValidationError(
object sender, ValidationErrorEventArgs e )
{
if ( e.Action == ValidationErrorEventAction.Added )
{
QuantityOnHand.Background = new SolidColorBrush( Colors.Red );
clean = false;
}
else if ( e.Action == ValidationErrorEventAction.Removed )
{
QuantityOnHand.Background = new SolidColorBrush( Colors.White );
clean = true;
}
}
// page.xaml
<Grid x:Name="LayoutRoot" Background="White" BindingValidationError="LayoutRoot_BindingValidationError" >
<TextBox x:Name="QuantityOnHand"
Text="{Binding Mode=TwoWay, Path=QuantityOnHand,
NotifyOnValidationError=true, ValidatesOnExceptions=true }"
VerticalAlignment="Bottom"
HorizontalAlignment="Left"
Height="30" Width="90"red
Grid.Row="4" Grid.Column="1" />
// book.cs
public int QuantityOnHand
{
get { return quantityOnHand; }
set
{
if ( value < 0 )
{
throw new Exception( "Quantity on hand cannot be negative!" );
}
quantityOnHand = value;
NotifyPropertyChanged( "QuantityOnHand" );
} // end set
}