C# 扩展数据网格行错误
当我试图将行设置为用户选择的行时,我在标题中指出了这个错误。此行发生错误:C# 扩展数据网格行错误,c#,wpf,datagrid,C#,Wpf,Datagrid,当我试图将行设置为用户选择的行时,我在标题中指出了这个错误。此行发生错误: DataGridRow row = e.Row as DataGridRow; 错误消息:无法转换类型 “ExtendedGrid.Microsoft.Windows.Controls.DataGridRow”到 “System.Windows.Controls.DataGridRow”通过引用转换, 装箱转换、取消装箱转换、换行转换或null 类型转换 我正在使用WPF扩展数据网格。以下是RowDetailsVisi
DataGridRow row = e.Row as DataGridRow;
错误消息:无法转换类型
“ExtendedGrid.Microsoft.Windows.Controls.DataGridRow”到
“System.Windows.Controls.DataGridRow”通过引用转换,
装箱转换、取消装箱转换、换行转换或null
类型转换
我正在使用WPF扩展数据网格。以下是RowDetailsVisibilityChanged事件的源代码:
private void RowDetailsVisibilityChanged(object sender, ExtendedGrid.Microsoft.Windows.Controls.DataGridRowDetailsEventArgs e)
{
DataGridRow row = e.Row as DataGridRow;
FrameworkElement tb = GetTemplateChildByName(row, "RowHeaderToggleButton");
if (tb != null)
{
if (row.DetailsVisibility == System.Windows.Visibility.Visible)
{
(tb as ToggleButton).IsChecked = true;
}
else
{
(tb as ToggleButton).IsChecked = false;
}
}
}
有什么问题吗?看起来像是
e.Row
不是System.Windows.Controls.DataGridRow
。WPF扩展DataGrid的创建者必须创建自己的DataGridRow
类
您需要转换为正确的类型:
var row = e.Row as ExtendedGrid.Microsoft.Windows.Controls.DataGridRow;
您可能还需要调整代码的其余部分,具体取决于
ExtendedGrid.Microsoft.Windows.Controls.DataGridRow
类中实际可用的信息。谢谢@格兰特·温尼