<TextBox Name="txtAirWayBillTotal" Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=AirWayBillTotal}" Grid.Column="3" Grid.Row="5" Height="23" HorizontalAlignment="Stretch" Margin="0" VerticalAlignment="Top" Width="Auto" Grid.ColumnSpan="2" HorizontalContentAlignment="Right" FontWeight="Bold" IsReadOnly="True" Focusable="False" />The window has the AirWayBillTotal defined like this:
private decimal airwaybillTotal; public decimal AirWayBillTotal { get { return this.airwaybillTotal; } set { if (value != this.airwaybillTotal) { this.airwaybillTotal = value; this.OnPropertyChanged("AirWayBillTotal"); } } }I have this code too:
void AirWayBillDetail_StateChange(mmBaseBusinessObject bizObj, mmBusinessStateChangeEventArgs e) { if (e.State == mmBusinessState.Retrieved) { // Store the Air WayBill Detail in the DataGrid's data context this.grdAirWayBillDetails.DataContext = this.AirWayBillDetail.EntityList; // Hide the new item row place holder in the Air WayBill Detail DataGrid ((IEditableCollectionView)CollectionViewSource.GetDefaultView(grdAirWayBillDetails.ItemsSource)).NewItemPlaceholderPosition = NewItemPlaceholderPosition.None; } //this.ShowAirWayBillTotal(); if (this.AirWayBillDetail.EntityList != null) { this.AirWayBillTotal = this.AirWayBillDetail.EntityList.Sum(x => x.awd_amount); foreach (var c in this.AirWayBillDetail.EntityList) { c.PropertyChanged += CollectionItemChanged; } } }which as I understands it will call CollectionItemChanged whenever a value in the EntityList changes (but of course I may be misunderstanding).
void CollectionItemChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "awd_amount") { AirWayBillTotal = AirWayBillDetail.EntityList.Sum(x => x.awd_amount); OnPropertyChanged("AirWayBillTotal"); } }which checks if the value in the entitylist that was changed was awd_amount and if so, re-calculates the total.