Dynamic-data SourceList new added items does not refresh when selected/deselected

102 views Asked by At

I have a SourceList and a ReadOnlyObservableCollection.

    public SourceList<T> SourceList { get; set; } = new SourceList<T>();
    public ReadOnlyObservableCollection<T> ActiveList;

And bind applies with below code:

   SourceList.Connect()
      .Filter(criteria, ListFilterPolicy.ClearAndReplace)
      .Transform((item, i) => { item.DisplayOrder = i + 1; return item; })
      .Bind(out ActiveList)
      .Subscribe();

And the list displays in a window :

   listItemsControl.ItemsSource = ViewModel.ActiveList;

And I bind IsSelected of any item to IsChecked of a ToggleButton. Everything is good until I add new item to the SourceList. For new added items, the binding is not work.

Thanks for any idea to fix the problem.

1

There are 1 answers

0
drepamig On

If the criteria that you're filtering the SourceList on is checking against IsSelected, then you'll likely have to add an AutoRefresh:

   SourceList.Connect()
     .AutoRefresh(x=> x.IsSelected)
     .Filter(criteria, ListFilterPolicy.ClearAndReplace)
     .Transform((item, i) => { item.DisplayOrder = i + 1; return item; })
     .Bind(out ActiveList)
     .Subscribe();

By default, a SourceList will only push collection changes down the pipeline and won't account for property changes within any given item. By adding AutoRefresh, changes to that property within the source will cause its parent be sent down the pipeline.