如何执行datagrid的VirtualizingPanel的BringIndexIntoViewPublic方法

时间:2014-02-05 09:07:22

标签: c# wpf .net-4.5 virtualization

我正在尝试获取WPF VirtualizingPanel DataGrid的对象并希望执行方法BringIndexIntoViewPublic

但我从来没有在网上找到任何代码如何调用它?

如果有人知道如何访问DataGrid的VirtualizingPanel对象,请告诉我。

1 个答案:

答案 0 :(得分:0)

经过漫长的研发。我找到了解决方案: - )

        var selector = sender as MultiSelector;

        //// with this way you can call the scrolling item into view even if the items are virtualized.
        //// works only for VirtualizingPanel.VirtualizationMode="Standard" not for recycle mode.
        var itemsHost = typeof(MultiSelector).InvokeMember("ItemsHost", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance, null, selector, null);

        VirtualizingPanel virtualPanel = itemsHost as VirtualizingPanel;
        if (virtualPanel != null && selector.SelectedIndex >= 0)
        {
            virtualPanel.BringIndexIntoViewPublic(selector.SelectedIndex);
        }