在另一个 Scrollviewer 中使用 ScrollViewer
我的 wpf 应用程序的结构如下:
<Scrollviewer>
<Grid>
<Scrollviewer>
<DataGrid>
我的目标是,如果 DataGrid 超过屏幕的高度,则使用它自己的 Scrollviewer。目前仅使用外部 ScrollViewer,因此我必须滚动整个网格。
有人可以告诉我该怎么做吗?
The structure of my wpf application is like:
<Scrollviewer>
<Grid>
<Scrollviewer>
<DataGrid>
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在内部 ScrollViewer 上设置一个高度,否则它将根据其内容的大小拉伸所需的高度。
此外,DataGrid 还为其自己的 ScrollBar 提供了内置属性,您可以使用这些属性来代替将 DataGrid 包装在 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.
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 放置在 Scrollviewer 之外。因此,您可以设置两个 Grid.Rows,并让它为您划分可用大小(默认值为“相等”,或者如果您仅使用两行,则为 50%-50%)。因此,如果 DataGrid 超出其可用大小,它将使用自己的 ScrollViewer。如果下面的内容超出了大小,它将使用您手动放置的ScrollViewer。至少,这就是我根据您最初的输入解决它的方法。请随意添加代码/注释,以便我们找到更好的方法。
如果您将两个 ScrollViewer 加上一个数据网格放置在彼此内部,如果您想要这种细粒度的控制,您将被迫开始传递具体的高度或宽度值。
You might want to place the DataGrid outside the Scrollviewer then. Therefore you can set two Grid.Rows, and let it part the available size for you (default would be "equal" or if you use only two rows, 50%-50%). So if the DataGrid exceeds its available size it will use its own ScrollViewer. If the content below is exceeding the size, it will use your manually placed ScrollViewer. At least, that is how i would solved it based on your initial input. Feel free to add code / comments so we might find a better way.
If you place two ScrollViewers plus a datagrid inside each other you will be forced to start passing out concrete Height or Width values if you want that kind of fine grained control.