从Silverlight DataGrid中的索引获取行 [英] Get Row from Index in Silverlight DataGrid

查看:151
本文介绍了从Silverlight DataGrid中的索引获取行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Silverlight DataGrid中实现重新排序行。为此,我将扩展默认的 DataGridDragDropTarget ,我需要覆盖并实现以下方法:

I am trying to implement reordering rows in a Silverlight DataGrid. For this I am extending the default DataGridDragDropTarget, and I need to override and implement the following method:

protected override DataGridRow ContainerFromIndex(DataGrid itemsControl, int index)
{

}

如何从DataGrid和索引获取DataGridRow?

How can I get the DataGridRow from the DataGrid and the Index?

推荐答案

A Herzmeister的回答略有改善,请参阅评论:

A slight improvement on Herzmeister's answer, see comments:

protected override DataGridRow ContainerFromIndex(DataGrid itemsControl, int index)
{
    var rowsPresenter = itemsControl.GetVisualDescendants().OfType<DataGridRowsPresenter>().FirstOrDefault();
    if (rowsPresenter != null)
    {
        return rowsPresenter.Children.OfType<DataGridRow>()
                .Where(row => row.GetIndex() == index).SingleOrDefault();
    }
    return null;
}

这篇关于从Silverlight DataGrid中的索引获取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆