1

SilverlightDataGrid滚动,DataGrid触发一个RowLoading事件。如何阻止滚动事件触发RowLoadingRow事件?

4

2 回答 2

2

由于行是虚拟化的,因此会触发 RowLoading 事件。使用虚拟化,只有在屏幕上可见时才会创建(和加载)行。因此,每次向下或向上滚动时,都会创建、加载一个新行并触发 RowLoading 事件。

要禁用虚拟化,您可以尝试设置此属性:

VirtualizingStackPanel.VirtualizationMode="Standard"

请注意,如果您有很多行,这会降低网格的性能。

于 2013-09-07T09:09:10.847 回答
2

我希望这会有所帮助,这在 Silverlight 中运行。

    void grid_LoadingRow(object sender, DataGridRowEventArgs e)
    {
        YourViewModel vm = this.DataContext as YourViewModel;
        //prevent the LoadingRow on Scroll
        if (vm.NumRowsLoaded >= vm.NumRowsTotal)
            return;
        vm.NumRowsLoaded += 1;


        RowObject c = e.Row.DataContext as RowObject;
        if (c != null)
        {
            //Your styling options
        }
    }

收取数据时,您必须在 ViewModel 中控制 NumRowsLoaded 和 NumRowsTotal。

于 2016-06-08T10:54:07.590 回答