Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

MVVM Binding not bubbling add new element from collection

$
0
0

Hello,
I've implemented a component which displays a simple view. The view is bounded to my user control throught the ItemTemplate (based on DataTemplate type) as we could do for a ListView or any other controls which can display views.
My user control also implements an ItemsSource property, which should make that my user control displays the ItemTemplate view as many times the ItemsSource property contains record of data. There is also a static readonly BindableProperty

the ItemsSource is of type IEnumerable, and a BindablePropery is bound to this one.

When I starts my application, initializing some data to the ItemsSource property, my component displays correctly the views.
I have three buttons also on my page.
the first one updates a property of the class holding the data. It works fine as the display is updated accordingly to the code.
The second one add a new element to the collection and nothing happens on the page. The created element is not displayed.
The third one remove the first element of the collection. Here also, nothing changes on the display of my component. Menwhile, if I press again the update button, the deleted element is not refreshed meaning that my component (at least MVVM) knows that this element does not exists anymore.

On my ViewModel, when an element is added or removed from the collection, the CollectionChanged event is triggered, which triggers also the OnPropertyChanged event. But my component is not listening this event whereas, at initialization, it receives correctly this event (and therefore, displays the views).

What should I do in order my component is called when updating the collection ?
Both the ViewModel and the Model itself implements the INotifyPropertyChanged interface. Making only my ViewModel implementing this interface makes that none of the buttons works.

Many thanks for any help.


Viewing all articles
Browse latest Browse all 75885

Trending Articles