locked
Why a ListVIew don't Scroll? RRS feed

  • Question

  • Hi,

    I have a ListView and can't scroll unless use a fix width.
    I can't use a fix width because I use SizeChanged to update
    a TextBlock.
    What I am doing wrong?

         <ListView x:Name="FoodDListView"
                              Visibility="Visible"
                              AutomationProperties.AutomationId="FoodDListView"
                              AutomationProperties.Name="FoodD Group"    
                              ScrollViewer.VerticalScrollBarVisibility="Visible"
                              ScrollViewer.VerticalScrollMode="Enabled"
                              BorderThickness="1"
                              BorderBrush="Yellow"
                              Background="Navy"
                              ItemsSource="{Binding FoodDs}"
                              SelectionChanged="foodDListView_SelectionChanged"
                              SizeChanged="foodDListView_SizeChanged"
                        >
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Grid Width="500" Height="58" >
                                    <StackPanel Orientation="Horizontal" Width="500" >

                                        <StackPanel Orientation="Horizontal" Background="Blue" Width="390">
                                            <Rectangle x:Name="placeholderRectangle"
                                       Fill="Red"
                                       Opacity="0"/>
                                             <TextBlock Text="Id:"  Margin="0,0,5,0" Visibility="Collapsed"/>
                                            <TextBlock Text="{Binding _id}"
                                                       Visibility="Collapsed"
                                                        x:Name="_idTextBlock"
                                                     />
                                           
                                            <TextBlock Text="{Binding description}"
                                                      x:Name="descriptionTextBlock"  Margin="0,10,0,0"/>
                                            <TextBlock Text=" = "  Margin="0,10,0,0" Visibility="Visible"/>
                                            <TextBlock x:Name="caloriesTextBlock"
                                                Text="{Binding calories}" Margin="0,10,0,0"/>
                                            <TextBlock Text=" Calories:" Margin="0,10,0,0"/>
                                        </StackPanel>

                                    </StackPanel>
                                    <StackPanel Orientation="Vertical" Margin="395,0,0,0">
                                        <Button Content="Delete" Margin="0,10,0,0"  Command="{Binding DataContext.DeleteCommand, ElementName=FoodDListView}"
                                                CommandParameter="{Binding _id}"                                      
                                                />
                                   
                                    </StackPanel>

                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>

                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapGrid MaximumRowsOrColumns="5" VerticalChildrenAlignment="Top"
                              HorizontalChildrenAlignment="Left" Orientation="Horizontal"/>
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                       
                    </ListView>


    ADRIAN DIBU

    Tuesday, January 14, 2014 11:57 PM

Answers

  • Hi,

    When the size of the ItemsControl's viewport isn't restricted, the control doesn't perform virtualization. So you cannot scroll the listview in your app.

    See Using virtualization with a list or grid to get more information.

    And you can place a ListView inside a Grid. The viewport of the ListView is restricted to the size of the parent Grid:

    <Grid Height="400" Width="600">
    <ListView/>
    ...
    <Grid>
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by adibu Friday, January 17, 2014 12:46 AM
    Wednesday, January 15, 2014 6:02 AM