Reputation:
I have a DataGridTextColumn but when I click to enter the cell the text now becomes editable, but when I double click on the text it will not select all the text (or just the current word).
<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" />
Upvotes: 0
Views: 1528
Reputation: 81
One of solutions, is set style for datagirdcells, that sets MouseDoubleClick event for each unit.
<Window.Resources>
<Style TargetType="DataGridCell">
<EventSetter Event="MouseDoubleClick" Handler="CellDoubleClick"/>
</Style>
</Window.Resources>
And code behind...
/// <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();
}
Upvotes: 1