Cysharp / ObservableCollections

High performance observable collections and synchronized views, for WPF, Blazor, Unity.
MIT License
461 stars 36 forks source link

In WPF, is it necessary to re-ToNotifyCollectionChanged after re-assigning an ObservableList? #34

Open CodingOctocat opened 2 months ago

CodingOctocat commented 2 months ago
// WPF simple sample.

ObservableList<int> list;
public ISynchronizedView<int, int> ItemsView { get; set; }

public MainWindow()
{
    InitializeComponent();
    this.DataContext = this;

    list = new ObservableList<int>();
    ItemsView = list.CreateView(x => x).ToNotifyCollectionChanged();

    BindingOperations.EnableCollectionSynchronization(ItemsView, new object()); // for ui synchronization safety of viewmodel
}

protected override void OnClosed(EventArgs e)
{
    ItemsView.Dispose();
}

private void DoStuff()
{
    list = GetData();
    // 👇??? Should I always Clear the list and then AddRange the data?
    ItemsView = list.CreateView(x => x).ToNotifyCollectionChanged();

    BindingOperations.EnableCollectionSynchronization(ItemsView, new object()); // for ui synchronization safety of viewmodel
}