I have this scenario:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
...
</StackPanel>
<ScrollViewer
Grid.Row="1"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Settings}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
...
</ItemsControl>
</ScrollViewer>
<Button Content="Add Row" Grid.Row="2" VerticalAlignment="Top"/>
</Grid>
I want the "Add Row" button to stay at the bottom of the ItemsControl, but I want that ItemsControl to start scrolling and the "Add Row" button to be pinned to the bottom of the window (so always visible), whenever the number of rows would exceed the window bounds. I can pin the button to the bottom of the control with "auto" row size for row 1, and I can pin it to the bottom of the window and allow the itemscontrol to scroll with "*" row size, but I can't seem to get both simultaneously.
Is there a clean way to achieve this?
I did try to force the MaxHeight of the scrollviewer, but that got ugly fast.
adding VerticalAlignment="Top"
for outer Grid achieves necessary pinning
<Grid VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
...
</StackPanel>
<ScrollViewer
Grid.Row="1"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Settings}" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
...
</ItemsControl>
</ScrollViewer>
<Button Content="Add Row" Grid.Row="2" VerticalAlignment="Top"/>
</Grid>