Reputation: 2285
I've got some XAML like this:
<Grid HorizontalAlignment="Center" ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<ListBox Grid.RowSpan="3" ItemsSource="{Binding OverrideEntityList}" Margin="5" Height="200" Width="250" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
<ComboBox Grid.Column="1" ItemsSource="{Binding GeometryType}" SelectedIndex="0" Margin="5" SelectionChanged="ComboBox_SelectionChanged"/>
<Grid x:Name="AddLineGrid" Grid.Row="1" Grid.Column="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Length:" Margin="5"/>
<TextBox Grid.Column="1" Text="{Binding OverrideLength}" Width="50" Margin="5"/>
<Label Grid.Row="1" Content="Angle:" Margin="5"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding OverrideAngle}" Width="50" Margin="5"/>
</Grid>
<Grid x:Name="AddArcGrid" Grid.Row="1" Grid.Column="1" Visibility="Collapsed">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Diameter:" Margin="5"/>
<TextBox Grid.Column="1" Text="{Binding OverrideLength}" Width="50" Margin="5"/>
<Label Grid.Row="1" Content="Angle:" Margin="5"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding OverrideAngle}" Width="50" Margin="5"/>
</Grid>
<Button Grid.Row="2" Grid.Column="1" Content="Add" Command="{Binding AddOverrideEntityCommand}" Margin="5"/>
</Grid>
I'm trying to get the ListBox to fill the whole column, but only be a certain height (because I don't want it to expand when items are added - just the scrollbar to appear).
The XAML designer in Visual Studio shows me what I would expect:
But the resulting view when I build my program doesn't seem to respect the Grid.RowSpan of the ListBox:
Is there a conflict between setting the Height on the ListBox along with the Grid.RowSpan? Or is there something else I'm missing?
Upvotes: 0
Views: 969
Reputation: 169340
Is there a conflict between setting the Height on the ListBox along with the Grid.RowSpan? Or is there something else I'm missing?
The ListView does span all 3 rows but since it only has a height of 200 and the height of the window is larger than this, it naturally won't be able to fill the entire column from top to bottom.
You should set the height of the ListView
to the same height as the window for this to happen. You can do this initially using a OneTime
binding:
<ListBox Grid.RowSpan="3" ItemsSource="{Binding OverrideEntityList}" Margin="5" Height="{Binding Height, RelativeSource={RelativeSource AncestorType=Window}, Mode=OneTime}" Width="250" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
Upvotes: 1