First, your layout is a mess. Why do you need to put the StackPanel as the only child of the Grid . For strings? Use RowDefinitions and ColumnDefinitions When Working With Grid
From my understanding of your layout, you can pretty much do everything you need with just the Grid and DockPanel . When working with container layouts, strive to ensure that your layout with the least number of containers is "effective." Even if this does not bring any real benefits to the job, it is extremely helpful when navigating through the code of another user so as not to have excessive nesting.
<Grid x:Name="Main"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" FontSize="24" Text="Dynamic data " /> <TextBlock Grid.Row="1" FontSize="24" Text="height " /> <TextBlock Grid.Row="2" FontSize="24" Text="unknown... " /> <ScrollViewer Grid.Row="3" Background="Red"> <StackPanel> <TextBlock FontSize="24" Text="Result set... 0" /> <TextBlock FontSize="24" Text="Result set... 1" /> <TextBlock FontSize="24" Text="Result set... 2" /> <TextBlock FontSize="24" Text="Result set... 3" /> </StackPanel> </ScrollViewer> <DockPanel x:Name="Nav" Grid.Row="4" LastChildFill="False"> <Button Content="Back" DockPanel.Dock="Left" /> <Button Content="Forward" DockPanel.Dock="Right" /> </DockPanel> </Grid>
This should give you everything you are looking for. If you need to limit Height dimensions to static values, add them accordingly when absolutely necessary.
Regarding the โNavโ DockPanel , yes, you can use the HorizontalAlignment so that your Button is left and right and thus does not use the DockPanel , but this would contradict the concept of trying to save the โoneโ in the Grid cell and therefore using the DockPanel .
source share