在刷新有界集合的数据后,我们有一个焦点问题,即聚焦 DataGrid 的一个单元格。例如,我们为其集合设置一个过滤器,然后我们想要重新聚焦存储列的存储单元格。
我们是否认为对 ScrollIntoView 的调用是同步的,这是否意味着在调用它之后创建了我们想要的行和单元格并且我们可以设置焦点?(这再次意味着在我们调用 ScrollIntoView 之后,我们是否认为 Itemsgenerator 完成了它的工作并且我们可以找到我们想要的单元格)
$
//set filter of DataGrid Collection
DataGrid_Standard.ScrollIntoView(rowNumber,cellNumber);
//we sure our desired cell are created now
DataGridRow row = (DataGridRow)DataGrid_Standard.ItemContainerGenerator.ContainerFromIndex(index);
if (row == null)
{
// may be virtualized, bring into view and try again
DataGrid_Standard.ScrollIntoView(DataGrid_Standard.Items[index]);
row = (DataGridRow)DataGrid_Standard.ItemContainerGenerator.ContainerFromIndex(index);
}
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer);
// try to get the cell but it may possibly be virtualized
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
// now try to bring into view and retreive the cell
DataGrid_Standard.ScrollIntoView(rowContainer, DataGrid_Standard.Columns[column]);
cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); cell.focus();