이 WPF DataGrid
데이터 템플릿이 있습니다 :WPF Datagrid에서 Enter 키를 누르면 DataGridCellsPanel.BringIndexIntoView의 ArgumentOutOfRangeException이 발생합니까?
<DataGrid
CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
CanUserSortColumns="False"
SelectionMode="Single" SelectionUnit="FullRow" GridLinesVisibility="Horizontal"
IsEnabled="{Binding Enabled}"
ItemsSource="{Binding ValuesDataTable}"
CellEditEnding="DataGrid_CellEditEnding"/>
여기에 이벤트 처리기가 :
private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.EditAction == DataGridEditAction.Commit)
{
var textBox = e.EditingElement as TextBox;
var dataGrid = (DataGrid)sender;
var viewModel = dataGrid.DataContext as IHasEditableCell;
viewModel.EditCell(e.Row.GetIndex(), e.Column.DisplayIndex, textBox.Text);
dataGrid.CancelEdit();
}
}
이 키를 PropertyChanged
발생시키는보기 모델의 ValuesDataTable
속성에 PropertyChanged
이벤트 DataGrid
은에 바인딩됩니다.
셀을 편집하고 클릭하면 정상적으로 작동합니다. 그러나 편집 할 때 셀을 편집하고 Enter 키를 누르면이 런타임 예외가 발생합니다.
System.ArgumentOutOfRangeException was unhandled
Message=Specified argument was out of the range of valid values.
Parameter name: index
Source=PresentationFramework
ParamName=index
StackTrace:
at System.Windows.Controls.DataGridCellsPanel.BringIndexIntoView(Int32 index)
at System.Windows.Controls.Primitives.DataGridCellsPresenter.ScrollCellIntoView(Int32 index)
at System.Windows.Controls.DataGrid.ScrollCellIntoView(Object item, DataGridColumn column)...
... 이상합니다. 이 문제를 어떻게 해결할 수 있을지 생각해?