Reputation:
I have some XAML code, and my problem is that the Listview height does not stay within the bounds of the Grid row but rather, grows with the amount of ListViewItem's added. This prevents the list from scrolling.
How can I prevent this?
Here is some reproduced xaml code:
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Grid Margin="30, 20, 30, 20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0">
<TextBlock Text="SomeText" FontSize="40"/>
</StackPanel>
<StackPanel Grid.Row="1">
<TextBlock Text="Some More Text" FontSize="30"/>
</StackPanel>
<Grid x:Name="ContGrid" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Viewbox HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="0" Stretch="None" Width="AUto">
<StackPanel x:Name="holderPanel" Margin="5" Grid.Column="0" Grid.Row="0" Orientation="Vertical">
<TextBlock Text="SomeCategories" FontSize="20"/>
<ListView CanDragItems="True" CanReorderItems="True" AllowDrop="True" Width="380">
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Green">Test</ListViewItem>
<ListViewItem Background="Purple">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Green">Test</ListViewItem>
<ListViewItem Background="Purple">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Green">Test</ListViewItem>
<ListViewItem Background="Purple">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
<ListViewItem Background="Green">Test</ListViewItem>
<ListViewItem Background="Purple">Test</ListViewItem>
<ListViewItem Background="Blue">Test</ListViewItem>
<ListViewItem Background="Red">Test</ListViewItem>
</ListView>
</StackPanel>
</Viewbox>
</Grid>
</Grid>
</Grid>
Upvotes: 1
Views: 1679
Reputation:
The reason the ListView's height grew with the amount of ListViewItems added, is because the ListView is placed inside a StackPanel. StackPanel's will allow to stretch beyond the bounds of the screen without ever enabling the scroll bar.
Here is a link to the original answer
Upvotes: 1