【问题标题】:Extended DataGrid row error扩展 DataGrid 行错误
【发布时间】:2014-03-17 21:57:47
【问题描述】:

当我尝试将行设置为等于用户选择的行时,我收到了标题中所述的错误。此行发生错误:

DataGridRow row = e.Row as DataGridRow;

错误信息:无法转换类型 'ExtendedGrid.Microsoft.Windows.Controls.DataGridRow' 到 'System.Windows.Controls.DataGridRow' 通过引用转换, 装箱转换、拆箱转换、包装转换,或为空 类型转换

我正在使用 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;
            }
        }

 }

有什么建议吗?

【问题讨论】:

    标签: c# wpf datagrid


    【解决方案1】:

    看起来e.Row 不是System.Windows.Controls.DataGridRow。 WPF Extended DataGrid 的创建者必须创建自己的DataGridRow 类。

    您需要转换为正确的类型:

    var row = e.Row as ExtendedGrid.Microsoft.Windows.Controls.DataGridRow;
    

    您可能还需要调整其余代码,具体取决于 ExtendedGrid.Microsoft.Windows.Controls.DataGridRow 类中实际可用的信息。

    【讨论】:

    • 谢谢! @格兰特温尼
    猜你喜欢
    • 1970-01-01
    • 2016-07-22
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-27
    • 2012-01-02
    相关资源
    最近更新 更多