How I can implement a function depending Checkbox changes into Datagrid?

Multi tool use
How I can implement a function depending Checkbox changes into Datagrid?
I have a requierement in WPF, I have a ViewModel with a long property called TotalImport and a ObservableCollection called CuentasxCobrar
CxC is a class with a long property called Import, and a bool property called Selected
The CuentasxCobrar is the ItemSource of a Datagrid into my View
I must calculate TotalImport as the sum of Import for each element with Selected on true
My ViewModel Works fine, but the function that calculate TotalImport never is called
#region CuentasxCobrar
private ObservableCollection<CxC> _cuentasxcobrar;
public ObservableCollection<CxC> CuentasxCobrar
{
set
{
_cuentasxcobrar = value;
**ActualizaImporteAcumulado();**
OnPropertyChanged("CuentasxCobrar");
OnPropertyChanged("ImporteAcumulado");
}
get { return _cuentasxcobrar; }
}
#endregion
#region ActualizaImporteAcumulado
private void ActualizaImporteAcumulado()
{
_importeacumulado = 0;
foreach (var item in _cuentasxcobrar)
{
_importeacumulado += item.seleccionada ? item.importepago : 0;
}
OnPropertyChanged("ImporteAcumulado");
}
#endregion
But when I made click on the Checkbox into my Datagrid, that was bound to the property Selected, the change to the Cuentas x Cobrar is not called
Investigating I find this:
How to rewrite this DataGrid MouseLeftButtonUp binding to MVVM?
But never is called the MouseLeftButtonUpCommand function
I made in my ViewModer this:
#region MouseLeftButtonCommand
private RelayCommand _mouseLeftButtonUpCommand;
public RelayCommand MouseLeftButtonUpCommand
{
get
{
return _mouseLeftButtonUpCommand
?? (_mouseLeftButtonUpCommand = new RelayCommand(
() =>
{
ActualizaImporteAcumulado(); // the handler goes here
}));
}
}
public class RelayCommand : ICommand
{
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
private Action methodToExecute;
private Func<bool> canExecuteEvaluator;
public RelayCommand(Action methodToExecute, Func<bool> canExecuteEvaluator)
{
this.methodToExecute = methodToExecute;
this.canExecuteEvaluator = canExecuteEvaluator;
}
public RelayCommand(Action methodToExecute)
: this(methodToExecute, null)
{
}
public bool CanExecute(object parameter)
{
if (this.canExecuteEvaluator == null)
{
return true;
}
else
{
bool result = this.canExecuteEvaluator.Invoke();
return result;
}
}
public void Execute(object parameter)
{
this.methodToExecute.Invoke();
}
}
#endregion
And in my View:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
........
</DataGrid>
.....
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonDown" >
<i:InvokeCommandAction Command="{Binding MouseLeftButtonUpCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</DataGrid>
What is wrong?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.