Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CollectionItemChanged not Firing
Message
From
22/03/2013 06:18:53
 
 
To
21/03/2013 13:24:09
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01568945
Message ID:
01569004
Views:
25
>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!)

Presumably the problem is that updating the grid in the above scenario does not fire the CollectionItemChanged (should be easy to check using a trace) ?

What binding is set on the relevant DataGridTextColumn? If UpdateSourceTrigger is not set to PropertyChanged you could try that.

If you save using the 'Alt-S' is the changed value in the focussed textbox actually saved ? If not then you have a problem even before sorting the totals update.
Maybe you could monitor for the 'Alt-S' and move the focus from the textbox to trigger the CollectionItemChanged
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform