WPF工具包 - 适合数据网格的高度,以内容的高度 [英] WPF Toolkit - Fit datagrid height to content height
问题描述
我有一个WPF数据网格,并希望它的高度等于它的行+头的高度之和。
I have a WPF datagrid and would like it's height to equal the sum of the heights of it's rows + header.
即。如果我的DataGrid标题是100px的,我有4行,身高每50像素我的DataGrid的总高度应为300像素。
i.e. if my datagrid header is 100px and I have 4 rows, each 50px in height the total height of my datagrid should be 300px.
是否有声明指定的高度应符合总和它的内容的方式?
Is there a way of declaratively specifying that the height should match the sum of it's contents?
在此先感谢!
推荐答案
能否请您粘贴code?因为你所要求的可以通过将数据网格到面板,这将不是一个控制所需的尺寸范围内限制其规模,并安排它完全可以简单地实现。
Could you please paste your code? Because what you are asking can be simply achieved by placing DataGrid into a panel, which will not constrain its size and arrange it exactly within desired size of a control.
在换句话说,你可以把它放在StackPanel中垂直方向,这就是它:
In other words, you can place it inside StackPanel with vertical orientation, and that's it:
<Window x:Class="WpfApplication5.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dg="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
Title="Grid Sample"
Height="300"
Width="300">
<StackPanel>
<dg:DataGrid ItemsSource="{Binding}">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Header="No."
Width="SizeToCells"
Binding="{Binding CheckNumber}"
IsReadOnly="True" />
<dg:DataGridTextColumn Header="Date"
Binding="{Binding Date, StringFormat=d}" />
<dg:DataGridTextColumn Header="Pay To"
MinWidth="200"
Binding="{Binding Recipient}"
CanUserSort="False" />
</dg:DataGrid.Columns>
</dg:DataGrid>
</StackPanel>
</Window>
这篇关于WPF工具包 - 适合数据网格的高度,以内容的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!