locked
Why has the vertical scroll bars disappeared from my listview? RRS feed

  • Question

  • I had a ListView control, in a grid's row, specifying the grid's row and column.  When I had it like that, then vertical scroll bars showed up fine, when there were more rows than was display.

    Now I've moved the ListView into a stack panel, so that I could put a textblock control over it.  And I've moved the positioning in the grid's row, from the ListView to the stack panel.  However, now the vertical scroll bars have disappeared.  Why? How do I get them back? (Below is the relevant XAML):

    		<StackPanel Grid.Column="0" Grid.Row="2" HorizontalAlignment="Center">
    		<TextBlock Name="tbDisplayMatches"></TextBlock>
    		<ListView Margin="5" Name="lstClients" SelectionMode="Single" SelectionChanged="lstClients_SelectionChanged">
    			<ListView.View>
    				<GridView>
    					<GridView.Columns>
    						<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=ClientName}" />
    						<GridViewColumn Header="Client Number" DisplayMemberBinding="{Binding Path=ClientNumber}" />
    						<GridViewColumn Header="Case" DisplayMemberBinding="{Binding Path=CaseNumber}" />
    						<GridViewColumn Header="Appointment" DisplayMemberBinding="{Binding Path=AppointmentDate, Converter={StaticResource DateConverter} }" />
    						<GridViewColumn Header="SSN" DisplayMemberBinding="{Binding Path=SocialSecurityNo}" />
    						<GridViewColumn Header="DOB" DisplayMemberBinding="{Binding Path=DateOfBirth, Converter={StaticResource DateConverter} }" />
    						<GridViewColumn Header="Contract" DisplayMemberBinding="{Binding Path=IsContractClient}" />
    					</GridView.Columns>
    				</GridView>
    			</ListView.View>
    		</ListView>
    		</StackPanel>
    

     


    Rod
    Thursday, May 6, 2010 7:58 PM

Answers

  • The problem is that listview cant autosize inside stackpanel so the listview is actually the height of the items it contains and does not autosize to the size of the stackpanel. Grid autosizes to its container. You need to either specify a height for the listview, Set row height to auto, or go back to using grid instead of stackpanel.

    • Marked as answer by Rod at Work Friday, May 7, 2010 4:54 PM
    Friday, May 7, 2010 3:29 PM

All replies

  • What listview control are you using?
    Friday, May 7, 2010 1:53 PM
  • I'm not sure I understand what you're asking.  I got into XAML view and just entered <ListView> and started typing the markup.  Did that answer your question?

     


    Rod
    Friday, May 7, 2010 2:54 PM
  • Ahh I meant are you using WPF or Silverlight? There is no silverlight listview by default so you must be using WPF.
    Friday, May 7, 2010 3:16 PM
  • The problem is that listview cant autosize inside stackpanel so the listview is actually the height of the items it contains and does not autosize to the size of the stackpanel. Grid autosizes to its container. You need to either specify a height for the listview, Set row height to auto, or go back to using grid instead of stackpanel.

    • Marked as answer by Rod at Work Friday, May 7, 2010 4:54 PM
    Friday, May 7, 2010 3:29 PM
  • Ahh I meant are you using WPF or Silverlight? There is no silverlight listview by default so you must be using WPF.

    Sorry, I'm using WPF.
    Rod
    Friday, May 7, 2010 4:42 PM
  • The problem is that listview cant autosize inside stackpanel so the listview is actually the height of the items it contains and does not autosize to the size of the stackpanel. Grid autosizes to its container. You need to either specify a height for the listview, Set row height to auto, or go back to using grid instead of stackpanel.


    I pulled the ListView out of the stack panel, and set the height of the row the ListView sits in.

    Thank you for your help!


    Rod
    Friday, May 7, 2010 4:54 PM