Workaround:
Use the commit edit command and on it update the aggregate value:
public partial class MainPage : ContentPage
{
public ObservableCollection<InvoiceItem> Items { get; } = new()
{
new InvoiceItem { Price = 100m },
new InvoiceItem { Price = 200m },
new InvoiceItem { Price = 300m },
};
public MainPage()
{
InitializeComponent();
BindingContext = this;
this.dataGrid.Commands.Add(new CustomDataGridEditingCommand());
}
}
public class InvoiceItem : INotifyPropertyChanged
{
private const decimal FullTaxRate = 0.19m;
private const decimal HalfTaxRate = 0.07m;
private decimal price;
private decimal prop1;
private decimal prop2;
public bool SupressPropertyChanged { get; set; }
public decimal Price
{
get => price;
set
{
if (SetProperty(ref price, value))
{
this.UpdateAggregates();
}
}
}
public decimal Prop1
{
get => prop1;
set => SetProperty(ref prop1, value);
}
public decimal Prop2
{
get => prop2;
set => SetProperty(ref prop2, value);
}
public event PropertyChangedEventHandler? PropertyChanged;
protected void RaisePropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public void UpdateAggregates()
{
if (this.SupressPropertyChanged)
{
return;
}
Prop2 = price * HalfTaxRate;
Prop1 = price * FullTaxRate;
}
private bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value))
{
return false;
}
field = value;
RaisePropertyChanged(propertyName);
return true;
}
}
public class CustomDataGridEditingCommand : DataGridCommand
{
public CustomDataGridEditingCommand()
{
this.Id = DataGridCommandId.CommitEdit;
}
public override void Execute(object parameter)
{
if (parameter is EditContext context)
{
var item = context.CellInfo.Item as InvoiceItem;
item.SupressPropertyChanged = true;
this.Owner.CommandService.ExecuteDefaultCommand(DataGridCommandId.CommitEdit, parameter);
item.SupressPropertyChanged = false;
this.Owner.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(10), () => item.UpdateAggregates());
}
}
} <telerik:RadDataGrid x:Name="dataGrid"
ItemsSource="{Binding Items}"
AutoGenerateColumns="False"
ShowColumnFooters="True">
<telerik:RadDataGrid.Columns>
<telerik:DataGridNumericalColumn PropertyName="Price"
HeaderText="Price">
<telerik:DataGridNumericalColumn.AggregateDescriptors>
<telerik:PropertyAggregateDescriptor PropertyName="Prop1"
Function="Sum" />
<telerik:PropertyAggregateDescriptor PropertyName="Prop2"
Function="Sum" />
</telerik:DataGridNumericalColumn.AggregateDescriptors>
</telerik:DataGridNumericalColumn>
</telerik:RadDataGrid.Columns>
</telerik:RadDataGrid>Regards,
Didi
Progress Telerik