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
C# 如何访问DataGrid.RowDetailsTemplate中文本块内的数据_C#_Wpf_Xaml - Fatal编程技术网

C# 如何访问DataGrid.RowDetailsTemplate中文本块内的数据

C# 如何访问DataGrid.RowDetailsTemplate中文本块内的数据,c#,wpf,xaml,C#,Wpf,Xaml,如何从TextBlock Name=“txtSellerId” 您可以将模型绑定到数据网格行,并在代码隐藏中使用它 var user = (User)myDataGrid.SelectedItem; var userId = user.Id; 一个简单的例子:要以编程方式获取值,可以尝试此方法 dgUsers.LoadingRowDetails += dgUsers_LoadingRowDetails; void dgUsers_LoadingRowDetails(object sende

如何从
TextBlock Name=“txtSellerId”


您可以将模型绑定到数据网格行,并在代码隐藏中使用它

var user = (User)myDataGrid.SelectedItem;
var userId = user.Id;

一个简单的例子:

要以编程方式获取值,可以尝试此方法

dgUsers.LoadingRowDetails += dgUsers_LoadingRowDetails;

 void dgUsers_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
       {
         var textBlockValue = (e.DetailsElement as FrameworkElement).FindName("txtSellerId") as TextBlock;
       }    

既然是绑定值,为什么不处理viewmodel中的数据而不是从ui中获取数据?
dgUsers.LoadingRowDetails += dgUsers_LoadingRowDetails;

 void dgUsers_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
       {
         var textBlockValue = (e.DetailsElement as FrameworkElement).FindName("txtSellerId") as TextBlock;
       }