我有一个DataGridTextColumn,但当我单击输入单元格时,文本现在变为可编辑,但当我双击文本时,它不会选择所有文本(或仅选择当前单词)。
<DataGridTextColumn ClipboardContentBinding="{Binding Path=Name}" SortMemberPath="Name"
Header="Name"
Binding="{Binding Path=Name, Mode=TwoWay, UpdateSourceTrigger=Explicit}" CanUserReorder="True" CanUserSort="True" CanUserResize="True" Width="SizeToHeader" />发布于 2014-01-22 00:10:11
其中一种解决方案是为数据单元设置样式,为每个单元设置MouseDoubleClick事件。
<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();
}https://stackoverflow.com/questions/20523443
复制相似问题