扩展数据网格行错误
本文关键字:错误 网格 数据网 数据 扩展 | 更新日期: 2023-09-27 17:50: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;
}
}
}
有什么建议吗?
看起来e.Row
不是System.Windows.Controls.DataGridRow
。WPF扩展数据网格的创建者必须已经创建了自己的DataGridRow
类。
你需要转换为正确的类型:
var row = e.Row as ExtendedGrid.Microsoft.Windows.Controls.DataGridRow;
您可能还需要根据ExtendedGrid.Microsoft.Windows.Controls.DataGridRow
类中实际可用的信息来调整代码的其余部分。