无法获取WPF数据网格行

时间:2014-08-04 10:09:28

标签: wpf c#-4.0 prism wpfdatagrid avalondock

在我的wpf应用程序中,我每30分钟发布一个事件,它会在所有打开的窗口上重新绑定自动生成的数据网格,之后我遍历每行datagrid以执行某些操作。我使用下面的方法获取自动生成的wpf datagrid的所有行。

public static IEnumerable<DataGridRow> GetDataGridRows(DataGrid grid)
{
    var itemsSource = grid.ItemsSource as IEnumerable;
    if (null == itemsSource) yield return null;
    foreach (var item in itemsSource)
    {
       var row = grid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
       if (null != row) yield return row;
    }
}

它适用于活动窗口(活动选项卡)并返回所有行,但对于其他窗口(非活动选项卡),它返回null。

(注意:在我的应用程序中,窗口以选项卡格式排列,我使用Avalon Dock作为停靠窗口控件。)

0 个答案:

没有答案
相关问题