我正在构建一个wpf应用程序,我有一个DataGrid,用户可以在其中编辑单元格,当我单击要编辑的单元格时,总文本被选中,如下图所示:

当用户单击要编辑的单元格时,我希望文本如下图所示:

发布于 2018-02-19 15:11:48
CS
实现内置DataGrid的CustomDataGrid
public class CustomDataGrid : DataGrid
{
protected override void OnPreparingCellForEdit(DataGridPreparingCellForEditEventArgs e)
{
base.OnPreparingCellForEdit(e);
var textbox = e.EditingElement as TextBox;
if (textbox == null) return;
textbox.Focus();
textbox.CaretIndex = textbox.Text.Length;
}
}XAML
<CustomDataGrid>
</CustomDataGrid>https://stackoverflow.com/questions/48860802
复制相似问题