我正在使用ListBox,ItemsPanel设置为VirtualizingStackPanel。
<ListBox ItemsSource="{Binding Items}"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"
VirtualizationMode="Recycling"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataGrid
VerticalAlignment="Top"
HeadersVisibility="None"
ItemsSource="{Binding Distances}">
<DataGrid.Columns>
<DataGridTemplateColumn IsReadOnly="True" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FactDistance}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NormDistanceValue}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
TextAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding NormLiterature}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
TextAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
看起来不错:http://i.stack.imgur.com/53KLx.png
但是当我通过轻轻拖动拇指进行水平滚动时,会出现奇怪的额外空间 http://i.stack.imgur.com/GHl8k.png
当我调整窗口大小时,额外的空间会神奇地消失。它从何而来?如何摆脱它?
如果我使用简单的StackPanel,一切都很好,但我需要使用虚拟化。