Datagrid动态设置高度 [英] Datagrid set height dynamically

查看:208
本文介绍了Datagrid动态设置高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello,
       In my WPFapplication I have data grid... which can collapse and expand... But my problem is now when the Data grid is expanding the height of data grid is being increased... But when clicking collapse after expanding the records are collapsed , but the height of data grid is being constant. Can any one please advice me that how to set the height of data grid dynamically in WPF c#

推荐答案

你可以设置你

Horizo​​ntalAlignment =拉伸和

VerticalScrollBarVisibility = Auto



如果这不起作用,将网格的高度绑定到窗口高度因此它不会自动增长以适应它的内容。



高度={Binding RelativeSource = {RelativeSource AncestorType = {x:Type Window}},Path = ActualHeight}(可能是RenderSize.ActualHeight insetad只是ActualHeight)



另一种替代方法是使用DockPanel而不是Grid,因为该控件不会自动成长以适应它的内容。相反,它会拉伸它的最后一个孩子来填充所有剩余的空间。
You can set you
HorizontalAlignment=Stretch and
VerticalScrollBarVisibility=Auto

If this doesn't work,Bind the Grid's Height to the Window Height so it doesn't auto-grow to fit it's contents.

Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}" (It might be RenderSize.ActualHeight insetad of just ActualHeight)

Another alternate is to use 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.


这篇关于Datagrid动态设置高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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