如何在Scrollviewer上方获取页脚
本文关键字:获取 方获取 Scrollviewer | 更新日期: 2023-09-27 18:26:10
我有一个Scrollviewer,里面有一个ItemsControl。ItemsControl可以使用SCrollViewer滚动,也可以不滚动,具体取决于其中的项目数。我有一个控件,它显示所有项目的一些总值。此控件需要刚好位于ItemsControl之下。如果项目不多,它将位于最后一个项目的下方,而不是页面的底部,两者之间有很大的空间。我无法做到这一点。有人有什么想法吗?这里是我的一些代码:
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DockPanel Grid.Row="0">
<!-- This is my Total Control - just a Border for the example -->
<Grid Margin="0,4" MaxHeight="60" VerticalAlignment="Top" DockPanel.Dock="Bottom">
<Border Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
</Grid>
<ScrollViewer HorizontalContentAlignment="Stretch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
>
<ItemsControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ItemsSource="{Binding Path=ListeQuestions}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<concUCQuest:UCQuestion HorizontalAlignment="Stretch" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
这里有一个链接到我试图获得的图片
我尝试了DockPanel、Grid到Grid,但我已经没有主意了。
谢谢你的帮助!
在Scrollviewer中添加VerticalAlignment="Stretch"
就可以了。
<Grid>
<DockPanel LastChildFill="True">
<!-- This is my Total Control - just a Border for the example -->
<Grid DockPanel.Dock="Bottom">
<Border Background="Red" Height="10"/>
</Grid>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<ItemsControl HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl.ItemTemplate>
<DataTemplate>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</DockPanel>
</Grid>
这对我有用。
您也可以将ListBox与DataTemplate一起使用,而不是使用ScrollViewer包装ItemsControl。