Given the following XMAL why is no vertical scrollbar for the ListBox which is bound to an ObservableCollection of 100 strings. If I change the height of the second row from * to something fixed like 500 then a scrollbar appears, but obviously i want the row height to be what ever is available (which is what I understand * to mean)
<UserControl x:Class="SimpleStack.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.Resources>
<DataTemplate x:Key="ListBoxItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Place holder"/><TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Azure">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="The Text" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
<ListBox ItemsSource="{Binding ListOfNumbers}" Grid.Row="1" Grid.Column="0"
ItemTemplate="{StaticResource ListBoxItemTemplate}"/>
<TextBlock Text="Place Holder" Grid.Row="1" Grid.Column="1"/>
</Grid>
</UserControl>
The
*row height is in fact “everything else available” (if you have multiple *s, it would divy that up). I am guessing that your actual issue is that “whatever is available” is infinite. Most likely the usercontrol is being given an unlimited amount of space, so it is expanding to take up as much room as it needs. Make sure you’re limiting your usercontrol to the actual visible space and your listbox should get its scrollbar.