HI,
Im using the following code in order to support validation to textBox,currently what I need is very simple
I have a internal list with specific fields ,what I need is to mark the textBox with red boarder when the user
is typing any value that are not in the string list,
This is the first time that i use validation ruls and its not working for me ,The debugger is not invoked in validate method...
any idea how to make it work?
namespace ValidRuls01 { public class MyValidationRule : ValidationRule { public override ValidationResult Validate(object value, CultureInfo cultureInfo) { List<string> list = new List<String> {"FirstName", "LastName", "BusinessItem", "BusinessItems"}; bool isValid = list.Any(x => x.Contains(value.ToString())); ValidationResult result = null; result = isValid ? new ValidationResult(true, null) : new ValidationResult(false, null); return result; } } }
<Window x:Class="ValidRuls01.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:ValidRuls01" Title="MainWindow" Height="350" Width="525"><Grid><TextBox x:Name="TextBox1" Margin="208,150,234,143"><TextBox.Text><Binding Path="BoundProperty1" UpdateSourceTrigger="PropertyChanged"><Binding.ValidationRules><local:MyValidationRule /></Binding.ValidationRules></Binding></TextBox.Text></TextBox></Grid></Window>