I am trying to create a validation dependency between 2 datagrid columns.
The first column is a drop down box. (DataGridTemplateColumn) The second is a text column. (DataGridTextColumn)
I am trying from the drop down box event in the code behind to force the validation of the datagrid text column cell of the same row.
Thanks for your help.
<data:DataGridTemplateColumn Header="Type" >
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Source={StaticResource TypeListContainer}, Path=TypeLists}" Loaded="TypeBoxLoaded" DropDownClosed="TypeBoxChanged">
</ComboBox>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTextColumn Header="Rule" Binding="{Binding RuleWrapper, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" x:Name="RuleCol" />
Here is the property
public string RuleWrapper
{
get
{
return this.Rule;
}
set
{
//Required
if (value == null || value == string.Empty)
{
throw new ValidationException("Rule is required");
}
//Match regular expression if type is channel
Regex reg = new Regex(@"^(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)\.(51[01]|50[0-9]|[0-4]?[0-9][0-9]?)$");
if (Type == "channel" && !reg.IsMatch(value))
throw new ValidationException("Channel not matching the right format");
//Match range if type is trunk
int intValue = -1;
//Match if is a number
if (int.TryParse(value, out intValue))
{
//Match if number is in the range
if (intValue < 0 || intValue > 134217727)
throw new ValidationException("Trunk value must be between 0 and 134317727");
}
else
throw new ValidationException("Trunk value must a an integer");
this.Rule = value;
}
}

RuleWrapper = RuleWrapper, but I'm not sure that it is what you need. - vortexwolf