cimbalino/Cimbalino-Toolkit

Binding ObservableCollection updates one time

Closed this issue · 3 comments

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.

<behaviors:MultiBindingItem Value="{Binding prop1.collection.Count}"/> - to fire update event
<behaviors:MultiBindingItem Value="{Binding prop1.collection}"/> - to get actual data converter

Please, let me know if there is standard solution.

Regards,
Maksim

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!

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

Add/Remove buttons for adding and removing ObservableCollection items.

Regards,
Maksim

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...