是否有一种将项目添加到 ReactiveAsyncCommand 中的 ObservableCollection 的方法,或者我是否必须使用 Dispather?处理这种情况的 RxUI 方式是什么?
编辑:在 LoadData 运行时,应将项目一一加载到集合中。
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
MaxRows = 100;
Translations = new ReactiveCollection<string>();
LoadDataCommand = new ReactiveAsyncCommand();
LoadDataCommand.RegisterAsyncAction(_ => LoadData());
InitializeComponent();
this.DataContext = this;
}
private void LoadData()
{
for (int i = 1; i < MaxRows; ++i)
{
Thread.Sleep(100);
// What's the RxUI Way for this?
this.Dispatcher.Invoke(() => Translations.Add(i.ToString()));
}
}
public int MaxRows { get; set; }
public ReactiveCollection<string> Translations { get; set; }
public ReactiveAsyncCommand LoadDataCommand { get; set; }
}