Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.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# DataGrid单击单元格内容/文本_C#_.net_Wpf_Datagrid_Cell - Fatal编程技术网

C# DataGrid单击单元格内容/文本

C# DataGrid单击单元格内容/文本,c#,.net,wpf,datagrid,cell,C#,.net,Wpf,Datagrid,Cell,因此,我需要单击或双击DataGrid单元格的单元格文本内容。阅读了大量的问题后,我似乎不明白如何在WPF中完成WinForms中如此琐碎的任务 从中,我找到了一个至少适用于.NET 4.5.2的解决方案: var element = dg.CurrentColumn == null ? null : dg.Columns[dg.CurrentColumn.DisplayIndex].GetCellContent(dg.SelectedItem); var text = element.GetT

因此,我需要单击或双击DataGrid单元格的单元格文本内容。阅读了大量的问题后,我似乎不明白如何在WPF中完成WinForms中如此琐碎的任务

从中,我找到了一个至少适用于.NET 4.5.2的解决方案:

var element = dg.CurrentColumn == null ? null : dg.Columns[dg.CurrentColumn.DisplayIndex].GetCellContent(dg.SelectedItem);
var text = element.GetType() == typeof(TextBox) ? ((TextBox)element).Text : null;
Console.WriteLine(text);