您可以在Silverlight DataGrid中使用ScrollIntoView()与PagedCollectionView吗? [英] Can you use ScrollIntoView() with a PagedCollectionView in a Silverlight DataGrid?
问题描述
是否可以滚动到Silverlight中的特定行(按对象标识) DataGrid
有一个 ItemsSource
which是 PagedCollectionView
。
Is it possible to scroll to a particular row (by object identity) in a Silverlight DataGrid
that has an ItemsSource
which is a PagedCollectionView
.
我正在加载按天/状态等分组的订单列表。我需要能够滚动到一个特定的顺序。
I am loading a list of orders that are grouped by day/status etc. I need to be able to scroll to a particular order.
var pcv = new PagedCollectionView(e.Result.Orders);
gridOrders.ItemsSource = pcv;
不幸的是, ScrollIntoView(order)
因为 PagedCollectionView
。
Unfortunately, ScrollIntoView(order)
doesn't work because of the PagedCollectionView
.
来自MSDN的DataGrid的文章显示可以滚动到 PagedCollectionView
,但这并没有太多的用处。
An article on DataGrid from MSDN shows that it is possible to scroll to a group in a PagedCollectionView
, but that's not really much use.
foreach (CollectionViewGroup group in pcv.Groups)
{
dataGrid1.ScrollIntoView(group, null);
dataGrid1.CollapseRowGroup(group, true);
}
有没有办法呢?
推荐答案
是的,当项目源是 PagedCollectionView
。我使用您描述的组滚动方法,并将当前选定的项目滚动到视图中。为此,我有一个帮助方法,使用调度程序调用操作如下:
Yes, it is possible to scroll items into view when the item source is a PagedCollectionView
. I use both the group scrolling method you describe and I scroll the currently selected item into view. To do this, I have a helper method that uses the dispatcher to invoke the operation as follows:
private void ScrollCurrentSelectionIntoView()
{
this.dataGrid.Dispatcher.BeginInvoke(() =>
{
this.dataGrid.ScrollIntoView(
this.dataGrid.SelectedItem,
this.dataGrid.CurrentColumn);
});
}
我使用 BeginInvoke
,否则调用 ScrollIntoView
直接从事件处理程序调用时会失败(可能是因为 DataGrid
未正确更新其处理事件的状态。此方法可确保当前事件处理在调用滚动之前正确完成。
I used BeginInvoke
because otherwise, the call to ScrollIntoView
would fail when called directly from an event handler (presumably because the DataGrid
hadn't properly updated its state for the event being handled). This approach ensures that the current event handling completes properly before invoking the scroll.
这篇关于您可以在Silverlight DataGrid中使用ScrollIntoView()与PagedCollectionView吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!