Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CollectionItemChanged not Firing
Message
De
25/03/2013 09:39:36
 
 
À
22/03/2013 06:18:53
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Divers
Thread ID:
01568945
Message ID:
01569175
Vues:
37
>>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


Hi Viv,

I thought I had a reproducible scenario for this, but I'm having trouble working one out as the behaviour is not consistent. I'll have to dig some more to get one and get back to you on this.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform