Advertise with us

how do I make a datagrid fit the window height in wpf?

Hi developers!

I have a grid with 3 columns and 2 rows


            <ColumnDefinition Width="Auto"/>

            <ColumnDefinition Width="10"/>

            <ColumnDefinition Width="*"/>



            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>


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.

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


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

What to do?

thanks in advance

Last updated:7/19/2013 12:21:47 AM

1 Answers

shreesh chandra shukla
shreesh chandra shukla


You can try below line of code for make a datagrid fit the window height:-

<datagrid Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}"></datagrid>