Background
I need a grid with the following layout properties:
- 4 rows: header, main content, sub-content, footer
- The header is static content which isn't really affected by resize
- The main content needs to fill up all available space, with a minimum height of 180
- The sub-content is a RTB that can shrink and grow. This sub-content can eat up some of the main-contents space, but should always leave 180 pixels for the main-content. The sub-content should ideally only take up the minimum amount of area it needs. If there isn't much room left in the grid, the RTB should stop growing and instead enable its internal scrollviewer.
- The footer is like the header, static content unaffected by resize
The problem
The sub-content (RTB
) isn't auto-sizing itself to fit within the remaining space, nor is the vertical scroll-bar being enabled. This is causing anything below the main content to clip outside of the window.
Question
How can I get the RichTextBox
to shrink so that the footer is shown, allowing the user to scroll through the hidden RichTextBox
content, while simultaneously allowing the RichTextBox
to expand if the user stretches the window?
Below you will find a SSCCE which demonstrates what I'm trying to achieve and the issues that it's causing:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
MinWidth="200" MinHeight="300" Width="200" Height="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" MinHeight="180"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="10"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="Header" HorizontalAlignment="Center"/>
<Rectangle Grid.Row="1" Fill="Red"/>
<RichTextBox Grid.Row="2"
VerticalScrollBarVisibility="Visible"
Height="Auto"
Margin="0,5,0,0"
VerticalAlignment="Stretch"
BorderBrush="#FF818181"
BorderThickness="0.5"
Background="#FFEEEEEE"
FontSize="14">
<FlowDocument>
<List>
<ListItem>
<Paragraph>Lorem</Paragraph>
<Paragraph>IpSum</Paragraph>
<Paragraph>Lorem</Paragraph>
<Paragraph>IpSum</Paragraph>
</ListItem>
</List>
</FlowDocument>
</RichTextBox>
<TextBlock Grid.Row="3" Text="Footer" HorizontalAlignment="Center"/>
</Grid>
</Window>
Here is an image of the window when it's at its minimum size:
Here is an image of the window when it has been stretched to show all:
Extra information
I know that if I set the sub-content RowDefinition
to *
then the RichTextBox
works fine, except for the fact it takes too much room when the window is expanded. I need this area to take as much room as Auto
while behaving like *
.