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

Total Post:89


 5283  View(s)
Rate this:
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

  1. Re: how do I make a datagrid fit the window height in wpf?


    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>


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.