This is my code. What I want is for, inside the tab control, within the tab item, the scroll viewer to adapt to the exact size of the grid. When I open the program, the size is correct. When I drag the application to another, larger screen, the size adjusts correctly. However, when I return to the smaller screen, the size remains as it was on the larger screen.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel...>
<TabControl Grid.Row="1" Style="{DynamicResource TabControlDetailsView}" Margin="25,0,30,0" Focusable="False">
<TabItem Header="Description">
<Border Background="Black">
<Grid Margin="20" MaxHeight="{x:Static sys:Double.PositiveInfinity}">
<ScrollViewer VerticalScrollBarVisibility="Auto" Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Grid}}">
<HtmlTextView Content/>
</ScrollViewer>
</Grid>
</Border>
</TabItem>
</TabControl>
<Grid Grid.Row="2"...>
</Grid>
<Grid Grid.Column="1"...>
</Grid>
I also tried something simpler, like setting the Height of the ScrollViewer equal to that of the Grid, using Height='{Binding ElementName=test, Path=ActualHeight}'. It gave the same result as the code above. I also attempted to follow an online example by using a <RowDefinition Height="*"/> but it didn't work. In that case, the content of the HTML expanded completely, and the ScrollViewer didn't function.
I don't want to set a MaxHeight because I want the Grid and the ScrollViewer to adapt to the available space on the user's screen. If I set the MaxHeight, when switching to the larger screen, there's a large empty space above and below the Grid. And even though MaxHeight is a more feasible option, it wouldn't work for the layout idea I have in mind because my concept involves a page without a ScrollViewer, where the user chooses the information tab and it appears on the page only in the available space.
How do I make this grid, scroll viewer adapt to occupy only the available space, adjusting the size when switching screens?