admin管理员组文章数量:1309947
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.
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.
Share Improve this question asked Feb 4 at 2:42 Andy WynnAndy Wynn 1,2738 silver badges14 bronze badges1 Answer
Reset to default 1adding 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>
本文标签:
版权声明:本文标题:wpf - Pin a control to the bottom of another control, or the bottom of the window, whichever is higher - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741789332a2397567.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论