Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获取所有行的C#Wpf数据网格?_C#_Wpf_Datagrid - Fatal编程技术网

如何获取所有行的C#Wpf数据网格?

如何获取所有行的C#Wpf数据网格?,c#,wpf,datagrid,C#,Wpf,Datagrid,如何获取DataGrid中的所有DataGridRows? 像 当然错了,因为我需要每个DataGridRow元素,而不是struct for (int i = 0; i < postQueue.Items.Count; i++) { DataGridRow row = (DataGridRow)postQueue.ItemContainerGenerator

如何获取DataGrid中的所有DataGridRows? 像

当然错了,因为我需要每个DataGridRow元素,而不是struct

for (int i = 0; i < postQueue.Items.Count; i++)
            {
                DataGridRow row = (DataGridRow)postQueue.ItemContainerGenerator
                                                           .ContainerFromIndex(i);
                row.Header = i.ToString();
            }
for(int i=0;i
投掷
行为空

为什么不将数据网格绑定到一个ObservableCollection

XAML:

<DataGrid ItemsSource="{Binding Path=YourList}" >
...
</DataGrid>

由于
DataGrid
实现的UI虚拟化,当前不可见的项没有
DataGridRow
容器,因此可能存在重复项。您可以关闭此功能,但它会带来性能损失。为什么需要访问容器?我想自动将索引添加到datagrid的左侧
<DataGrid ItemsSource="{Binding Path=YourList}" >
...
</DataGrid>
private ObservableCollection<T> yourList = new ObservableCollection<Hole>();
public ObservableCollection<T> YourList
{
    get { return yourList; }
    set
    {
        this.yourList = value;
        NotifyPropertyChanged("YourList");
    }
}
foreach (T element in this.YourList)
{
   ...
}