CSLA validation for WPF Toolkit DataGrid DataTextColumn Binding.ValidationRules

CSLA validation for WPF Toolkit DataGrid DataTextColumn Binding.ValidationRules

Old forum URL: forums.lhotka.net/forums/t/7502.aspx


Kevin Jones posted on Monday, August 24, 2009

I am trying to write XAML to validate a datagrid column using CSLA without having to write any extra code in the code behind but I have not been able to do it.
So far I can call a custom method that checks the BusinessBase.


In the XAML:
my:DataGridTextColumn.Binding
Binding.ValidationRules
local:CellDataInfoValidationRule ValidationStep="UpdatedValue"

Code Behind:
public class CellDataInfoValidationRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
// obtain the bound business object
BindingExpression expression = value as BindingExpression;
BusinessBase bb = expression.DataItem as BusinessBase;
if (!bb.IsValid)
{
return new ValidationResult(bb.IsValid, bb.BrokenRulesCollection.ToString());
}

return ValidationResult.ValidResult;
}
}

Is there a way that I can write my XAML to not need the code behind method? I would also like to display the validation for just one cell, not the entire row. My current method displays all of the broken rules.

RockfordLhotka replied on Monday, August 24, 2009

You can probably do what we did in CSLA .NET for Silverlight, which is to create custom column types for the grid, where the column renders a PropertyStatus control next to the content control (TextBox, ComboBox, etc).

Look in Csla\Silverlight in the SL version to see the code - it is probably pretty similar in WPF since I think they based the WPF grid somewhat off the SL grid.

Copyright (c) Marimer LLC