Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGridTextColumn双击全选_C#_Wpf_Xaml_Datagrid - Fatal编程技术网

C# DataGridTextColumn双击全选

C# DataGridTextColumn双击全选,c#,wpf,xaml,datagrid,C#,Wpf,Xaml,Datagrid,我有一个DataGridTextColumn,但当我单击进入单元格时,文本现在可以编辑,但当我双击文本时,它不会选择所有文本(或仅选择当前单词) 解决方案之一是为datagirdcells设置样式,为每个单元设置鼠标双击事件 <Window.Resources> <Style TargetType="DataGridCell"> <EventSetter Event="MouseDoubleClick" Handler="CellDouble

我有一个DataGridTextColumn,但当我单击进入单元格时,文本现在可以编辑,但当我双击文本时,它不会选择所有文本(或仅选择当前单词)


解决方案之一是为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();
    }