C# DataGridTextColumn双击全选
我有一个DataGridTextColumn,但当我单击进入单元格时,文本现在可以编辑,但当我双击文本时,它不会选择所有文本(或仅选择当前单词)C# DataGridTextColumn双击全选,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,我有一个DataGridTextColumn,但当我单击进入单元格时,文本现在可以编辑,但当我双击文本时,它不会选择所有文本(或仅选择当前单词) 解决方案之一是为datagirdcells设置样式,为每个单元设置鼠标双击事件 <Window.Resources> <Style TargetType="DataGridCell"> <EventSetter Event="MouseDoubleClick" Handler="CellDouble
解决方案之一是为datagirdcells设置样式,为每个单元设置鼠标双击事件
<Window.Resources>
<Style TargetType="DataGridCell">
<EventSetter Event="MouseDoubleClick" Handler="CellDoubleClick"/>
</Style>
</Window.Resources>
和代码隐藏
/// <summary>
/// Select all text in DataGridCell on DoubleClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CellDoubleClick(object sender, RoutedEventArgs e)
{
DataGridCell cell = null;
TextBox textBox = null;
cell = sender as DataGridCell;
if (cell == null)
{
return;
}
textBox = cell.Content as TextBox;
if (textBox == null)
{
return;
}
textBox.SelectAll();
}
//
///双击选择DataGridCell中的所有文本
///
///
///
私有void单元双击(对象发送方,路由目标)
{
DataGridCell=null;
TextBox TextBox=null;
cell=发送方作为DataGridCell;
if(单元格==null)
{
返回;
}
textBox=单元格。内容为textBox;
if(textBox==null)
{
返回;
}
textBox.SelectAll();
}
/// <summary>
/// Select all text in DataGridCell on DoubleClick
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CellDoubleClick(object sender, RoutedEventArgs e)
{
DataGridCell cell = null;
TextBox textBox = null;
cell = sender as DataGridCell;
if (cell == null)
{
return;
}
textBox = cell.Content as TextBox;
if (textBox == null)
{
return;
}
textBox.SelectAll();
}