【问题标题】:How to set DataGrid's BindingSource via XAML?如何在 XAML 中设置 DataGrid 绑定源?
【发布时间】:2012-04-13 09:44:08
【问题描述】:

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

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

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

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

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

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

【问题讨论】:

  • 任何显示集合的 WPF 控件都应绑定到 ObservableCollection&lt;&gt;
  • @Matten:你是对的。我已将类型更改为 observable 集合,它可以工作。
  • @ArsenZahray 如果将其添加为答案,那么您可以关闭您的问题。

标签: c# wpf xaml datagrid


【解决方案1】:

使用ObservableCollection&lt;&gt; 而不是List&lt;&gt;,因为它是为绑定而设计的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-03
    • 1970-01-01
    • 2019-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-15
    • 2023-03-16
    相关资源
    最近更新 更多