在wpf我如何使一个datagrid适合窗口高度 [英] in wpf how do i make a datagrid fit the window height

查看:1532
本文介绍了在wpf我如何使一个datagrid适合窗口高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有3列和2行的网格

I have a grid with 3 columns and 2 rows

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

我的左下方单元格,我有一个数据网格,AutoGenerateColumns = True可以加载多行。我想要做的是使数据网格高度最大化以适应窗口,并且为了让用户能够使用datagrid滚动条上下滚动条。

I the lower left cell, i have a data grid, with AutoGenerateColumns=True which can load many rows. What I want to do is for the data grid height to maximize to fit the window, and for the user to be able to use the datagrid scrollbar to scroll the rows up and down.

发生什么事情是datagrid窗口底部的流动,即使我设置了

What happens is that the datagrid flows of the bottom of the window, and even if i set the

ScrollViewer.VerticalScrollBarVisibility="Visible"

,滚动条没有影响,行向下流动。不知何故datagrid不受限制...

of the datagrid, the scrollbar has no effect and the rows flow downwards. Somehow the datagrid does not feel restricted...

该怎么办?

推荐答案

尝试设置DataGrid的 Horizo​​ntalAlignment = Stretch VerticalScrollBarVisibility = Auto

Try setting your DataGrid's HorizontalAlignment=Stretch and VerticalScrollBarVisibility=Auto

如果这不起作用,您可能还需要将网格的高度绑定到窗口高度,以使其不会自动扩展以适应其内容。通常我使用 Height ={Binding RelativeSource = {RelativeSource AncestorType = {x:Type Window}},Path = ActualHeight}(可能是 RenderSize.ActualHeight insalad只是ActualHeight ...我忘了。

If that doesn't work, you may also need to bind the Grid's Height to the Window Height so it doesn't auto-grow to fit it's contents. Usually I use Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}" (It might be RenderSize.ActualHeight insetad of just ActualHeight... I forget.

另一个选择是使用 DockPanel 而不是一个 Grid ,因为该控件不会自动增长以适应其内容,而是将其扩展为最后一个小孩以填充所有剩余空间。

Another alternative is to use a DockPanel instead of a Grid since that control doesn't auto-grow to fit it's contents. Instead it'll stretch it's last child to fill all remaining space.

这篇关于在wpf我如何使一个datagrid适合窗口高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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