开发者

Data Virtualization not working

I have been trying to gain performance by implementing virtualization for my ListView.

I use the following article to achieve that :

WPF: Data Virtualization By Paul McClean http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspx

the problem is that instead of loading just a couple of pages, all the pages are actually loaded which is weird. all the items are loaded when the Control is loaded.


Here is my ListView :

    <ListView ItemsSource="{Binding}"
              VirtualizingStackPanel.IsVirtualizing="True"
              VirtualizingStackPanel.VirtualizationMode="Recycling"
              ScrollViewer.IsDeferredScrollingEnabled="True">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel>

                </VirtualizingStackPanel>
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.View>
            <GridView>
                <GridViewColumn Width="250">
                    <GridViewColumn.Header>
                        <TextBlock Text="Part Number" Hor开发者_如何转开发izontalAlignment="Left"></TextBlock>
                    </GridViewColumn.Header>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Part.PartNumber}"></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

                <GridViewColumn Header="Description" Width="250">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Part.Description}"></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

                <GridViewColumn Header="Current Price" Width="250">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding CurrentPrice}"></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>

                <GridViewColumn Header="Old Price" Width="250">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding OldPrice}"></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>


I just realized that I was using a ScrollViewer (with property ScrollViewer.VerticalScrollBarVisibility="Visible") around my ListView which is why all the items were being loaded at once.

I removed it and everything now works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜