0

I am using a ListBox with ItemsPanel set to 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>

It looks ok: https://i.stack.imgur.com/53KLx.png

But when I do horizontal scrolling by quckly dragging the thumb, strange extra space appears https://i.stack.imgur.com/GHl8k.png

And when I resize the window, that extra space magically disappears. Where does it come from? How to get rid of it?

If I use simple StackPanel everything is fine, but I need to use virtualization.

Nadia
  • 11
  • 1
  • ListBox is already using VirtualizingStackPanel. You dont have to worry. Also no need for VirtualizationMode="Recycling" Just use ListBox the usual way without all your overrides – dev hedgehog Dec 16 '14 at 10:41
  • By default items are placed vertically. I need them horizontally, so i override the ItemsPanel. – Nadia Dec 16 '14 at 10:56
  • As soon you replace ItemsPanel with your custom VirtualizingStackPanel you will get those white spaces. Because the thing aint measuring properly anymore. That is why you have to resize the window which forces remeasuring of all elements and the white spaces disapear. Please remove Recycling Mode and try it out. Recycling might also cause this strange behavior. Just might. – dev hedgehog Dec 16 '14 at 12:06
  • Changed to VirtualizationMode="Standard", the problem remains... – Nadia Dec 17 '14 at 02:52

0 Answers0