SezMe
SezMe

Reputation: 527

Need explanation for data loading behavior of a 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?

Upvotes: 0

Views: 59

Answers (1)

mm8
mm8

Reputation: 169150

Why the difference in behavior?

The StackPanel disables the UI virtualization of the DataGrid because it measures its child elements with infinite vertical space:

Horizontal scroll for stackpanel doesn't work

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

Upvotes: 2

Related Questions