I have a Listbox with data-binding to payments of a project. When I add a new payment, the payment will be added to the list. The add-page is also used to edit the payments. The event is called, in debug-mode I can see the changed value of my payment, but the ListBoxItem is not going to be updated. At the end of the add-page an event will be called, which updates the listbox items:
GlobalNotifier.OnPaymentAdded();
The OnPaymentAdded calls a method which only notifies about the property changes:
OnNotifyPropertyChanged("Project");
The code of the listbox:
<ListBox Name="ListPayments" ItemsSource="{Binding Project.Payments}">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="10,5,10,0">
<StackPanel>
<TextBlock FontSize="30" Text="{Binding Name}" />
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Why are new items added, but existing items not updated? Any idea?
What’s happening is that although the
Project-object is updated, thePaymentsobject (presumably aList) is not.What you could try is the following:
List-object is being manipulated (edited, items removed / added), fire thePropertyChanged-event forProjectsList<Project>to anObservableCollection<Project>, which surely will fix your problemObservableCollectionis out of the question for you, implement an override for theOnNavigatedTo()in the view that shows the list, and call thePropertyChanged-events (Project, Payments etc) from there.Either one of these should fix your problem – it’s all a matter of taste and preferences.