我正在尝试获取WPF VirtualizingPanel
DataGrid
的对象并希望执行方法BringIndexIntoViewPublic
但我从来没有在网上找到任何代码如何调用它?
如果有人知道如何访问DataGrid的VirtualizingPanel对象,请告诉我。
答案 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);
}