从DataGrid更新ReactiveList更改单元格

时间:2017-08-07 16:35:16

标签: c# wpf reactiveui

我试图将ReactiveList绑定到DataGrid,我想绑定ItemChanged事件甚至Changed事件列表,以便我可以更新Total变量,该变量是列表中项目的总和。

这是我的清单声明:

private ReactiveList<AllocationMatrix> _matrixItems;
public ReactiveList<AllocationMatrix> MatrixItems
{
  get => _matrixItems; set => this.RaiseAndSetIfChanged(ref _matrixItems, value);
}

_matrixItems = new ReactiveList<AllocationMatrix>()
{ ChangeTrackingEnabled = true };

以下是我如何绑定到更改事件:

this.WhenAnyObservable(x => x._matrixItems.Changed)
.Subscribe(x =>
{
  Trace.WriteLine("Changed");
});

最后,我试图通过编辑单个单元格(而不是添加或删除行)来获取更改事件的数据网格。

<DataGrid x:Name="MatrixGrid"
  ItemsSource="{Binding MatrixItems, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"
...

由于某种原因,在编辑单元格时没有触发ChangedItemChanged事件,但是如果我添加或删除一行(这不是我需要的话)似乎会抛出。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:-1)

您可以尝试使用ObservableCollection<T>

例如:

ObservableCollection<int> collection = new ObservableCollection<int>();
var observable = Observable.FromEventPattern<NotifyCollectionChangedEventArgs>(collection,"CollectionChanged");

observable.Subscribe(a => { Console.WriteLine("Collection Changed !!!!! ");Debugger.Break(); });

collection.Add(1);

如果有帮助,请告诉我。

相关问题