VirtualizingStackPanel Scrollviewer height

shriram 125 Reputation points
2024-05-22T06:12:58.1066667+00:00

I am working a uwp app where i used ListView with VirtualizingStackPanel . In my case i am trying create an alternatives for CVS ListView so each item has a ItemsControl (choosen this because it consume less memory and ScrollViewer). Now if i want navigate to a item which is part of the nest list(ItemsControl element), i cant directly navigate to the element.

So i tried to adjust the scroll viewer in order to achieve this but the scrollable height and other details are not has a proper value, but the same with i can achieve if i use ItemsStackPanel instead of VirtualizingStackPanel.

<ListView

 x:Name="AuthorGroupsListView"

SelectionMode="None"

VirtualizingStackPanel.VirtualizationMode="Recycling"

 Margin="10">

<ListView.ItemTemplate>

    <DataTemplate x:DataType="local:AuthorBooksGroup">

        <StackPanel Background="Transparent">

            <TextBlock Text="{Binding Author}" FontWeight="Bold" FontSize="20" Margin="5"/>

            <ItemsControl

                          ItemsSource="{Binding Books}" >

                <ItemsControl.ItemTemplate>

                    <DataTemplate>

                        <StackPanel Margin="10" Background="Transparent" >

                            <TextBlock Text="{Binding Title}" FontSize="16" />

                            <TextBlock Text="{Binding Year}" FontSize="12" />

                        </StackPanel>

                    </DataTemplate>                        

                </ItemsControl.ItemTemplate>

            </ItemsControl>

        </StackPanel>

    </DataTemplate>

</ListView.ItemTemplate>

<ListView.ItemsPanel>

    <ItemsPanelTemplate>

        <VirtualizingStackPanel />

        <!--<ItemsStackPanel />-->

    </ItemsPanelTemplate>

</ListView.ItemsPanel>

</ListView>

Universal Windows Platform (UWP)
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,005 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
814 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Junjie Zhu - MSFT 18,476 Reputation points Microsoft Vendor
    2024-05-22T08:09:47.6366667+00:00

    Hi @shriram ,

    Welcome to Microsoft Q&A!

    I was able to reproduce the same behavior, after using VirtualizingStackPanel, the scrollable height changes while sliding, this should be by design.

    According to the official documentation, it is recommended that you use ItemsStackPanel or ItemsWrapGrid in listview.

    ItemsStackPanel is used as the default ItemsPanel for ListView. If you modify the ItemsPanel, we recommend you use ItemsStackPanel or ItemsWrapGrid instead of VirtualizingStackPanel or WrapGrid.

    Thank you.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.