【发布时间】:2015-08-27 14:19:00
【问题描述】:
我有一个包含几个名称 - 值对的 DataGrid,所述名称 - 值对是从硬件设备轮询的。为了提高性能(不是 UI 的轮询循环),我想知道显示了哪些绑定项。
<DataGrid Grid.Row="1" ItemsSource="{Binding ParameterViewSource.View}"
AutoGenerateColumns="False" CanUserReorderColumns="False"/>
DataGrid 现在默认虚拟化行。但是对于我的后台轮询循环,我想知道我的 CollectionViewSource 的哪些项目当前位于 RowPresenter 中。
该方法应该可以在 MVVM 中实现。
我尝试使用 DataGridRowsPresenter - 和 Children(或更具体的 DataContext),但我无法收到有关更改的通知。有什么简单的方法可以实现我想要的。
private static void GridOnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
DataGrid grid = (DataGrid)sender;
var rowPresenter = grid.FindChildRecursive<DataGridRowsPresenter>();
var items = rowPresenter.Children.OfType<DataGridRow>()
.Select(x => x.DataContext);
//Works but does not get notified about changes to the Children
//collection which occure if i resize the Grid, Collapse a
//Detail Row and so on
}
【问题讨论】:
-
能否提供一些代码