cimbalino / Cimbalino-Toolkit

:coffee: Cimbalino Toolkit
https://cimbalino.org
MIT License
114 stars 16 forks source link

Binding ObservableCollection updates one time #65

Closed Zaduvalo closed 6 years ago

Zaduvalo commented 6 years ago

Hi, I have problem with binding ObservableCollection, it reads values ones, not firing on collection modified. In xaml code bellow I have GridView binded to ObservableCollection and GridView items having another ObservableCollections bindings.

The first TextBox have generic binding, and it works fine, value updates after collection modified <TextBlock Text="{Binding prop1.collection.Count}"></TextBlock> But MultiBindingBehavior updates values ones, and not firing update on collection modify. <behaviors:MultiBindingItem Value="{Binding prop1.collection}"/>

<GridView ItemsSource="{Binding prop.collection }">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding prop1.collection.Count}"></TextBlock>
                        <TextBlock>
                             <interactivity:Interaction.Behaviors>
                                <behaviors:MultiBindingBehavior PropertyName="Text" Converter="{StaticResource MultiBindingValueConverter}" >
                                    <behaviors:MultiBindingItem Value="{Binding prop1.collection}"/>
                                    <behaviors:MultiBindingItem Value="{Binding prop2.collection}"/>
                                </behaviors:MultiBindingBehavior>
                            </interactivity:Interaction.Behaviors>
                        </TextBlock>
                    </StackPanel>
                </DataTemplate>
            </GridView.ItemTemplate>
</GridView>

P.S> I found if I am binding MultiBindingItem to ObservableCollection Count property it works, solution in this case will look a bit hacky, with unwanted extra items.

- to fire update event - to get actual data converter

Please, let me know if there is standard solution.

Regards, Maksim

pedrolamas commented 6 years ago

Hi Maksim, your code is a bit incomplete for me to test on my side, can you please provide the viewmodels for the binded properties? Thanks!

Zaduvalo commented 6 years ago

Hi Pedro. Take a look test app. App1.zip

Add/Remove buttons for adding and removing ObservableCollection items.

Regards, Maksim

pedrolamas commented 6 years ago

Thanks for the sample Zaduvalo, I now have the generic gist!

You have to remember there are two interfaces for notifications, INotifyPropertyChanged for property value changes and INotifyCollectionChanged for collection item changes.

When you bind to data.Count, you are effectively monitoring the Count property for changes and those are correctly raised, however, when you bind to data, that's monitoring for the data property changes and those are not raised as the instance didn't change, only the items inside the instance!

This is expected behavior from bindings and not a bug, so not much I can on my end I'm afraid...