Sim*_*ver 7 silverlight datagrid datagridview
是否可以在Silverlight DataGrid中滚动到特定行(按对象标识),该行具有ItemsSourcea PagedCollectionView.
我正在加载按日/状态等分组的订单列表.我需要能够滚动到特定订单.
var pcv = new PagedCollectionView(e.Result.Orders);
gridOrders.ItemsSource = pcv;
Run Code Online (Sandbox Code Playgroud)
不幸的是,ScrollIntoView(order)由于没有效果PagedCollectionView.
来自MSDN的一篇关于DataGrid的文章表明,可以滚动到a中的一个组PagedCollectionView,但这并没有太多用处.
foreach (CollectionViewGroup group in pcv.Groups)
{
dataGrid1.ScrollIntoView(group, null);
dataGrid1.CollapseRowGroup(group, true);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点 ?
是的,当项目来源为a时,可以将项目滚动到视图中PagedCollectionView.我使用您描述的组滚动方法,并将当前选定的项目滚动到视图中.为此,我有一个帮助方法,使用调度程序来调用操作,如下所示:
private void ScrollCurrentSelectionIntoView()
{
this.dataGrid.Dispatcher.BeginInvoke(() =>
{
this.dataGrid.ScrollIntoView(
this.dataGrid.SelectedItem,
this.dataGrid.CurrentColumn);
});
}
Run Code Online (Sandbox Code Playgroud)
我使用的BeginInvoke是因为否则,ScrollIntoView直接从事件处理程序调用时调用将失败(可能是因为DataGrid没有正确更新其处理事件的状态).此方法可确保在调用滚动之前正确完成当前事件处理.