In my WPF project, i have a Service
EF model defined as
public class Service
{
public int ID
public string Name
public decimal Price
}
and in my viewmodel i have.
public class ReceiptViewModel : BindableBase
{
private ObservableCollection<Service> _services;
public ObservableCollection<Service> Services
{
get { return _services; }
set { SetProperty(ref _services, value, () => RaisePropertyChanged(nameof(Total))); }
}
public decimal Total => Services.Sum(s => s.Price);
}
Total is bound to a textblock in my view and and my observable collection is bound to an itemscontrol with textbox inside.
i want my Total textblock to change everytime the user change one of the price in my collection from the UI. how can i achieve that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…