在另一个 Scrollviewer 中使用 ScrollViewer [英] Use ScrollViewer inside another Scrollviewer

查看:30
本文介绍了在另一个 Scrollviewer 中使用 ScrollViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 wpf 应用的结构是这样的:

The structure of my wpf application is like:

<Scrollviewer>
   <Grid>
       <Scrollviewer>
            <DataGrid>

我的目标是,如果 DataGrid 超过屏幕的高度来使用它自己的 Scrollviewer.目前只使用外部的 ScrollViewer,所以我必须滚动整个 Grid.

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.

谁能告诉我怎么做?

推荐答案

你需要在内部的 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 中使用 ScrollViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆