0

我在我的用户控件中使用绑定到 List 属性的 DataGrid:

<DataGrid x:Name="dataGrid" .... 
      ItemsSource="{Binding ItemSorce, ElementName=UserControl}" 
                            ....>                           

我的问题是每次更改源时都需要更新它。

我让用户控件实现 INotifyPropertyChanged 并引发 PropertyChanged 事件,但 DataGrid 原始内容保持不变。

我已经读过要更改 DataGrid,我应该在 ItemSorce 和绑定之间设置 BindingSource,但是我看到的所有示例都是通过 c# 源代码执行此操作的。

如何通过 xaml 设置 BindingSource,这是同步 DataGrid 和 ItemSorce 的最佳方式吗?

4

1 回答 1

2

使用 aObservableCollection<>而不是 a List<>,因为它是为绑定而设计的。

于 2012-04-13T09:56:56.527 回答