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?
答案 0 :(得分:2)
为什么行为不同?
StackPanel
禁用DataGrid
的UI虚拟化,因为它会测量具有无限垂直空间的子元素:
Horizontal scroll for stackpanel doesn't work
XAML/WPF - ScrollViewer which has StackPanel inside is not scrolling