Skip to content

Commit

Permalink
prevent focus to next cell when press return key in editing
Browse files Browse the repository at this point in the history
  • Loading branch information
soomin-kevin-sung committed Oct 23, 2023
1 parent c8e6394 commit 0349662
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/KevinComponent/FlexGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0349662

Please sign in to comment.