diff --git a/src/KevinComponent/FlexGrid.cs b/src/KevinComponent/FlexGrid.cs index ffb8c1d..2afa0db 100644 --- a/src/KevinComponent/FlexGrid.cs +++ b/src/KevinComponent/FlexGrid.cs @@ -37,6 +37,12 @@ public FlexGrid() "UnSelectAllByEscapeKey", typeof(bool), typeof(FlexGrid), new FrameworkPropertyMetadata(false)); + public static readonly DependencyProperty CellEditEndingCommandProperty = + DependencyProperty.Register( + "CellEditEndingCommand", + typeof(ICommand), + typeof(FlexGrid), + new FrameworkPropertyMetadata(null)); #endregion @@ -52,6 +58,24 @@ public bool UnSelectAllByEscapeKey set => SetValue(UnSelectAllByEscapeKeyProperty, value); } + public bool IsEditing + { + get + { + var row = (DataGridRow)ItemContainerGenerator.ContainerFromItem(CurrentCell.Item); + if (row == null) + return false; + + return row.IsEditing; + } + } + + public ICommand CellEditEndingCommand + { + get => (ICommand)GetValue(CellEditEndingCommandProperty); + set => SetValue(CellEditEndingCommandProperty, value); + } + #endregion #region Internal Properties @@ -210,6 +234,26 @@ public void PerformSort(DataGridColumn sortColumn) #region Protected Override Methods + protected override void OnPreviewKeyDown(KeyEventArgs e) + { + base.OnPreviewKeyDown(e); + + switch (e.Key) + { + case Key.Enter: + { + // 편집 중 Enter 클릭 시 + if (IsEditing) + { + // 적용하고 Enter 이벤트를 처리했다고 표기 + CommitEdit(DataGridEditingUnit.Row, true); + e.Handled = true; + } + } + break; + } + } + protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e);