How to refresh a WPF DataGrid?

前端 未结 7 1766
旧时难觅i
旧时难觅i 2020-12-14 07:15

I have a WPF DataGrid with some data. You can add rows through a separate window. The DataContext is the same, a LINQ-to-SQL object. Binding is also the same, I bind the \"I

7条回答
  •  无人及你
    2020-12-14 07:48

    The reason it's not updating is that LINQ-to-SQL doesn't implement INotifyCollectionChanged, so WPF has no way to tell that the ItemsSource has been updated. The least terrifying way to fix this, is to copy your LINQ-to-SQL results to an ObservableCollection - when you do the Insert, also add to the observable collection. Then you'll see the update.

提交回复
热议问题