ListView vertical scrollbar and height


  • Hi,


    I have a grid with three rows like this:

    <Grid x:Name="PropertiesGrids">


                            <RowDefinition Height="Auto"/>

                            <RowDefinition Height="Auto"/>

                            <RowDefinition Height="*"/>


                        <HeaderedContentControl Header="Overview" Style="{StaticResource HCCTemplate}" DockPanel.Dock="Top" Grid.Row="0">


                        <HeaderedContentControl Header="Properties" Style="{StaticResource HCCTemplate}" DockPanel.Dock="Top" Grid.Row="1">


                        <HeaderedContentControl Header="Search Result(s)" Style="{StaticResource HCCTemplate}" DockPanel.Dock="Top" VerticalContentAlignment="Stretch" Grid.Row="2">

                                <ListView x:Name="SearchResultsListBox" Width="260" SelectionChanged="SearchResultsListBox_SelectionChanged" SelectionMode="Single" HorizontalAlignment="Stretch" BorderThickness="0" Margin="2" MaxHeight="195" Background="White">




                                                <GridViewColumn Header="Result(s)">



                                                            <StackPanel ScrollViewer.VerticalScrollBarVisibility="Visible" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">


                                                                    <TextBlock Text="{Binding Path=Content.Score, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource InfoText}" />


                                                                <Image Source="{Binding Path=Content.ImageSource, RelativeSource={RelativeSource TemplatedParent}}" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="2" Stretch="Uniform" Width="150" Height="150" />











    the problem is that the listbox won't show the vertical scrollbar, and rows are going out of screen, btw I dynamically fill the listview during the application run.

    Wednesday, April 06, 2011 2:45 AM

All replies

  • I made a mistake in code, I don't want to set maxheight for listview, so in different resolution listview updates its height with scrollbars, btw I tried having scrollview inside datatemplate, it wont work, this part of code (grid) is my right side of screen, and I want it to fill the whole height and have vertical scrollbar on last headercontrol which contains listview
    Wednesday, April 06, 2011 3:09 AM
  • Hi,

    if u want to show scrollbViewer on the listView then try like this

    <ListView ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto"></ListView>

    and u have applided the scrolling on the stack panel that wont work..

    Panels are not templatable, so they cannot contain a ScrollViewer.  You could explicitly surround your DockPanel with a ScrollViewer, but setting the VerticalScrollBarVisibility property on the Panel will have no effect.  You must set it on the ScrollViewer or on some control whose template contains a ScrollViewer.

    try to put explicit ScrollViewer control on the stack panel...

    hope it helps u..

    Thanks, BHavik
    Wednesday, April 06, 2011 3:57 AM
  • Hi,

    If you will set height of ListView then your problem will be resolve.

    Hence, dynamically set the ActualHeight or Height, based on the screen resolution and your requirement.



    Wednesday, April 06, 2011 4:19 AM
  • @Rao: it won't work.


    @Patrik: I know that by setting height it shows scrollbars, but I want to do it automatically, if I bind the height or maxheight using systemparameters.workarea.height - something it won't work in multi monitor system, when user drags the application into another screen. how about that, is there any way to make it fit automatically to the screen. (this code is inside an stackpanel which fills my right side of screen)

    Wednesday, April 06, 2011 6:38 AM
  • Try putting the whole grid inside of a <DockPanel> tag. That worked for me.
    Tuesday, March 13, 2012 2:01 PM