Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.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# 扩展数据网格行错误_C#_Wpf_Datagrid - Fatal编程技术网

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
类中实际可用的信息。

谢谢@格兰特·温尼