WPF Toolkit - set document height to content height

I have a datagrid WPF and would like the height equal to the sum of the heights of its rows + header.

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 300 pixels.

Is there a way to declaratively indicate that the height should match the sum of the content?

0
source share
1 answer

Could you insert your code? Because what you are asking for can simply be achieved by placing the DataGrid in a panel that will not limit its size and arrange exactly within the required size of the control.

In other words, you can put it inside a StackPanel with a vertical orientation and that 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> 
+3
source

Source: https://habr.com/ru/post/917876/


All Articles