我有这种情况:
<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>
我希望“添加行”按钮停留在 ItemsControl 的底部,但我希望 ItemsControl 开始滚动,而“添加行”按钮固定在窗口底部(因此始终可见),只要行数超出窗口边界。我可以将按钮固定在控件底部,并将第 1 行的行大小设置为“自动”,也可以将其固定在窗口底部,并允许 itemscontrol 以“*”行大小滚动,但我似乎无法同时实现两者。
有没有一个干净的方法来实现这一点?
我确实尝试强制使用 scrollviewer 的 MaxHeight,但很快就变得很糟糕。