在另一个滚动查看器中使用ScrollViewer [英] Use ScrollViewer inside another Scrollviewer
问题描述
我的wpf应用程序的结构如下所示:
The structure of my wpf application is like:
<Scrollviewer>
<Grid>
<Scrollviewer>
<DataGrid>
我的目标是,如果DataGrid超过屏幕的高度以使用它自己的Scrollviewer。在这一刻,只有外部的ScrollViewer被使用,所以我必须滚动整个网格。
My Goal is, if the DataGrid exceeds the height of the screen to use it's own Scrollviewer. At the Moment only the outside ScrollViewer is used and so i have to scroll the whole Grid.
有人可以告诉我怎么做?
Can someone please tell me how to do this?
推荐答案
您需要在内部ScrollViewer上设置一个高度,否则它会根据内容的大小尽可能地扩展。
You need to set a height on the inner ScrollViewer, otherwise it'll stretch as much as it needs based on it's content's size.
<Window x:Name="RootWindow">
<ScrollViewer>
<Grid Height="{Binding ElementName=RootWindow, Path=ActualHeight}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="2*" />
</Grid.RowDefinitions>
<ScrollViewer Grid.Row="1">
<DataGrid />
</ScrollViewer>
</Grid>
</ScrollViewer>
</Window>
另外,DataGrid为它自己的ScrollBars提供了内置属性,您可以使用它来替代封装DataGrid在ScrollViewer中。这将滚动数据并始终保持标题可见,而不是滚动整个数据网格。
Also, the DataGrid has built-in properties for it's own ScrollBars which you can use instead of wrapping the DataGrid in a ScrollViewer. This will scroll the data and always leave the headers visible, instead of scrolling the entire datagrid.
<DataGrid HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto" />
这篇关于在另一个滚动查看器中使用ScrollViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!