Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CollectionItemChanged not Firing
Message
From
21/03/2013 13:24:09
 
 
To
All
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Title:
CollectionItemChanged not Firing
Miscellaneous
Thread ID:
01568945
Message ID:
01568945
Views:
46
I have a XAML window showing your typical master detail relationship between an Air Waybill (AWB) and the charges on the AWB. The AWB charges are displayed/edited in a grid and there is a textbox on the form which shows the total of the charges in the grid. The textbox is defined like this:
                        <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).

My CollectionItemChanged code is:
        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.

My problem (finally) is that in certain instances the total does not get updated. This occurs when I add a new row to the charges grid, type in the new amount in the awd_amount column and then use Alt+S to call the Save button's click event. If I tab out of the column the total is updated. It is similar to when using a toolbar in VFP the current control is apparently not losing focus so the change is not registering.

Any ideas how to fix this?

(Thanks for reading this far!)
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform