0

I have a wpf architecture question. On my xaml form, I have a main object (customer), two datagrids (customer's info).

On customer's properties, I have validation (using INotifyDataErrorInfo and exceptions in setters pattern). I have the same for some columns of both datagrids.

I'd like to have a Save button below to be enabled when all individual validations on fields are ok, and also when another supplementary rule is ok ("customer shoud have one address").

I was trying to find my way with multi data trigger conditions but feel like I'm messing out.

I'd like any change (a field validation becomes OK or NOK, when field looses focus) to immediately change Save button state, without taking too much processing time (I feel like I don't need to re-run all validation rules, just check HasError indicators) .

How should I organize relevant code:

  • to event attached to fields?
  • to multidatatriggers xaml part?
  • to code behind part?

Can I get access to a "global validation indicator" linked to a datagrid (which has cell validation templates).

Thank you for helping me getting points clearer.

barbara.post
  • 1,581
  • 16
  • 27

1 Answers1

1

This can be achieved quite easily, using the HasErrors property of your INotifyDataErrorInfo interface implementation. Assuming that you are using a Command of some sort for your save function, you can just add this property check into the CanExecute handler:

private bool CanSave(object parameter)
{
    return !((Customer)parameter).HasErrors;
}

...

public ICommand Save
{
    get { return new RelayCommand(action => SaveCustomer(), canExecute => 
        CanSave(SelectedClient)); }
}
Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • I will have muti triggers for my main object properties (error state) and check datagrid error state after click on button, then. – barbara.post Oct 07 '13 at 10:57
  • Here is a more explicative post that helped me understanding : http://stackoverflow.com/questions/9288507/disabling-button-based-on-multiple-properties-im-using-multidatatrigger-and-mu – barbara.post Oct 08 '13 at 20:08