I'm building a resolution-independent WPF application. The MainWindow uses a ContentControl to load views dynamically:
<Border Grid.Row="1" Grid.Column="1" BorderThickness="15,15,0,15" BorderBrush="{StaticResource GradientRARedOrange}">
<ScrollViewer
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto">
<ContentControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{Binding CurrentView}" />
</ScrollViewer>
</Border>
In one of these views, I have two DataGrids arranged in a Grid. They initially display correctly, but once data is loaded, both DataGrids expand vertically to fit all rows. As a result, the UserControl (view) grows, and the outer container (likely a ScrollViewer in a parent) shows a scrollbar, instead of the DataGrid itself showing internal scrollbars.
My expectation is: the DataGrid should stay within its allocated space (defined by Grid.Row with Height="*"), and show a scrollbar internally when content overflows.
The View:
<Grid Background="{StaticResource ColorMyColor2}" ClipToBounds="True">
<Grid.RowDefinitions>
<RowDefinition Height="15*"/>
<RowDefinition Height="70*"/>
<RowDefinition Height="15*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="65*"/>
<ColumnDefinition Width="15*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Row="1" Grid.Column="0" Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid x:Name=""
Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AutoGenerateColumns="False"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
SelectedItem="{Binding , Mode=TwoWay}"
ItemsSource="{Binding }"
Style="{StaticResource DataGridTheme1}">
<DataGrid.Columns>
<DataGridTextColumn Header="" Binding="{Binding }" />
</DataGrid.Columns>
</DataGrid>
</Grid>
<Grid Grid.Row="1" Grid.Column="1" Margin="20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid x:Name=""
Grid.Row="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
IsReadOnly="True"
SelectionMode="Single"
SelectionUnit="FullRow"
AutoGenerateColumns="False"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ItemsSource="{Binding Items}"
Style="{StaticResource DataGridTheme1}">
<DataGrid.Columns>
<DataGridTextColumn Header="" Binding="{Binding }" />
<DataGridTextColumn Header="" Binding="{Binding }" />
</DataGrid.Columns>
</DataGrid>
</Grid>
</Grid>
Style:
<Style TargetType="{x:Type DataGrid}"
x:Key="DataGridTheme1">
<Setter Property="Background" Value="{StaticResource ColorMyColor3}"/>
<Setter Property="Foreground" Value="{StaticResource ColorMyColor1}"/>
<Setter Property="RowBackground" Value="Transparent"/>
<Setter Property="AlternatingRowBackground" Value="{StaticResource ColorMyColor2}"/>
<Setter Property="GridLinesVisibility" Value="None"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="CanUserAddRows" Value="False"/>
<Setter Property="AutoGenerateColumns" Value="False"/>
<Setter Property="HeadersVisibility" Value="Column"/>
<Setter Property="RowHeaderWidth" Value="0"/>
<Setter Property="FontSize" Value="{StaticResource FontSizeMedium}"/>
<Setter Property="FontFamily" Value="{StaticResource FontPrimary}"/>
<Setter Property="Padding" Value="4"/>
<Setter Property="SelectionMode" Value="Single"/>
<Setter Property="SelectionUnit" Value="FullRow"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="MinHeight" Value="28"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontSize" Value="{StaticResource FontSizeMedium}"/>
<Setter Property="FontFamily" Value="{StaticResource FontPrimary}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="0" Opacity="0"/>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#EEE"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FFDDDDDD"/>
</Trigger>
</Style.Triggers>
<Style TargetType="DataGridCell">
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="DataGridCell">
<Border x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="4,0,4,0"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="border" Property="Background" Value="{StaticResource GradientRAOrangeRed}"/>
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource GradientRAOrangeRed}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
How can I force the DataGrid to stay within the height defined by its Grid.Row, and have the scrollbar appear inside the DataGrid, not in the parent container?
I don't want to use MaxHeight as the user should be able to resize the App as he wants.
I feel like I'm overlooking a simple but critical layout constraint.

<Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions>