using Avalonia.Controls; using ObservableCollections; using R3; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Threading; namespace AvaloniaApp { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = new ViewModel(); } } public class ViewModel { private ObservableList observableList { get; } = new ObservableList(); public INotifyCollectionChangedSynchronizedView ItemsView { get; } public ReactiveCommand AddCommand { get; } = new ReactiveCommand(); public ReactiveCommand ClearCommand { get; } = new ReactiveCommand(); public ViewModel() { observableList.Add(1); observableList.Add(2); //ItemsView = observableList.CreateView(x => x).ToNotifyCollectionChanged(SynchronizationContextCollectionEventDispatcher.Current); ItemsView = observableList.CreateView(x => x).ToNotifyCollectionChanged(); //var test = ItemsView.ToArray(); //INotifyCollectionChangedSynchronizedView // ItemsView = observableList.CreateView(x => x).ToNotifyCollectionChanged(); // BindingOperations.EnableCollectionSynchronization(ItemsView, new object()); AddCommand.Subscribe(_ => { ThreadPool.QueueUserWorkItem(_ => { observableList.Add(Random.Shared.Next()); }); }); // var iii = 10; ClearCommand.Subscribe(_ => { // observableList.Add(iii++); observableList.Clear(); }); } } }