如何获取所有行的C#Wpf数据网格?
如何获取DataGrid中的所有DataGridRows? 像 当然错了,因为我需要每个DataGridRow元素,而不是struct如何获取所有行的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
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)
{
...
}