WPF 数据网格与数据表绑定

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17899459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:18:06  来源:igfitidea点击:

WPF datagrid binding with datatable

wpfvb.netdatagriddatatable

提问by volderArt

I know that my datatable has data in it but I don't see it in my datagrid. here is my binding.

我知道我的数据表中有数据,但我在数据网格中看不到它。这是我的绑定。

<DataGrid Grid.Row="1" Name="DataGrid4" AutoGenerateColumns="TRUE" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False" AlternatingRowBackground="LightBlue" ItemsSource="{Binding Path=thisData.thisFollowUp.thisP.pData.dataTable.DefaultView}"/>

It is my understanding that I do not need to notify WPF when the datatable data has changed. Any Ideas what I am missing? I will add more code if it is necessary.

据我了解,当数据表数据发生变化时,我不需要通知 WPF。任何想法我缺少什么?如果有必要,我会添加更多代码。

采纳答案by OneFineDay

If you set the DataContextof the enclosing container for the DataGridyou just need to call ItemSource = {Binding}. You can set the DataContextafter you load the data in code behind. Examples

如果您为 设置了DataContext封闭容器的 ,则DataGrid只需调用ItemSource = {Binding}. 您可以DataContext在后面的代码中加载数据后设置。例子