WPF SelectedItem和滚动

Mad*_*Seb 5 wpf datagrid scroll

我有一个WPF DataGrid.DataGrid绑定到IList.该列表包含许多项,因此DataGrid MaxHeight设置为预定义值,DataGrid会自动显示滚动条.选择模式和单位设置为"单个完整行".

表单有一个名为"New"的按钮,它将一个项添加到datagrid绑定到的列表中.单击"New"后,新项应该是新选择的项.我这样做是通过:dataGrid.SelectedItem = newItem;

这有效..但不如我期望的那样好.

我还希望dataGrid 向下滚动到新选择的项目 ..有关如何执行此操作的任何想法?

此致,MadSEB

Ree*_*sey 9

设置SelectedItem后,请确保使用新项目调用DataGrid.ScrollIntoView.这将确保新项目在屏幕上可见.