Need explanation for data loading behavior of a datagrid

时间:2018-02-05 12:58:13

标签: wpf datagrid

I have a wpf window defined in XAML as follows:

<Window
    [The usual stuff]>
    <Window.Resources>
        [Some resources]
    </Window.Resources>
    <DockPanel>
        <ToolBarTray>
            [Two toolbars]
        </ToolBarTray>
        <DataGrid>
            [Stuff]
        </DataGrid>
    </DockPanel>
<Window>

The DataGrid has an ObservableCollection as the ItemsSource.

In this configuration, the DataGrid is populated as the user scrolls down through the data rows.

If I change the DockPanel to a StackPanel - and change nothing else - all rows of data are loaded when the window is Loaded.

Why the difference in behavior?

1 个答案:

答案 0 :(得分:2)

  

为什么行为不同?

StackPanel禁用DataGrid的UI虚拟化,因为它会测量具有无限垂直空间的子元素:

Horizontal scroll for stackpanel doesn't work

XAML/WPF - ScrollViewer which has StackPanel inside is not scrolling

相关问题