At the moment I have a grid and I'm trying to have a cell with validation rules. To validate it, I require the row's min and max value.
Validation Class:
public decimal Max { get; set; }
public decimal Min { get; set; }
public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
{
var test = i < Min;
var test2 = i > Max;
if (test || test2)
return new ValidationResult(false, String.Format("Fee out of range Min: ${0} Max: ${1}", Min, Max));
else
return new ValidationResult(true, null);
}
User Control:
<telerik:RadGridView SelectedItem ="{Binding SelectedScript}"
ItemsSource="{Binding ScheduleScripts}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn
DataMemberBinding="{Binding Amount}" Header="Amount"
CellTemplate="{StaticResource AmountDataTemplate}"
CellEditTemplate="{StaticResource AmountDataTemplate}"/>
<telerik:GridViewComboBoxColumn
Header="Fee Type"
Style="{StaticResource FeeTypeScriptStyle}"
CellTemplate="{StaticResource FeeTypeTemplate}"/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
FeeType Class:
public class FeeType
{
public decimal Min { get; set; }
public decimal Max { get; set; }
public string Name { get; set; }
}
I've tried this solution here WPF ValidationRule with dependency property and it works great. But now I come across the issue that the proxy can't be instantiated through the viewmodel. It's based on the row's selected ComboBox Value's Min and Max property.
For example, that combo box sample values are below
Admin Min: $75 Max $500
Late Min: $0 Max $50
Since a grid can have virtually as many rows as it wants, I can't see how creating proxies would work in my situation. If I can get some tips of guidance, would be greatly appreciated.
ComboBox
in your code. – GirvinValidationRule
, whereas it would be fairly easy to accomplish if you moved the validation logic to the view-model. – TicktackValidationRule
you could put the validation logic in your view-model together with implementingIDataErrorInfo
, and then useDataErrorValidationRule
which would do the rest of the job. For .Net 4.5 or later you could also useINotifyDataErrorInfo
+NotifyDataErrorValidationRule
instead. – Ticktack