Click here to Skip to main content
14,983,791 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using a ListBox with ItemsPanel set to VirtualizingStackPanel.
XML
<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.

But when I do horizontal scrolling by quckly dragging the thumb, strange extra space appears.

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.
Posted
Comments
Jan Bakker 17-Dec-14 3:16am
   
Try giving each textblock a different backgroundcolor.
You might be able to see what is happening.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900