---
title: "how do I make a datagrid fit the window height in wpf?"  
description: "how do I make a datagrid fit the window height in wpf?"  
author: "Takeshi Okada"  
published: 2013-07-18  
updated: 2013-07-19  
canonical: https://www.mindstick.com/forum/1323/how-do-i-make-a-datagrid-fit-the-window-height-in-wpf  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# how do I make a datagrid fit the window height in wpf?

Hi [developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs)!

I have a grid with 3 columns and 2 rows

<Grid.ColumnDefinitions>

<ColumnDefinition Width="[Auto](https://www.mindstick.com/forum/33810/remote-view-in-android-auto-cancel-custom-notification)"/>

<ColumnDefinition Width="10"/>

<ColumnDefinition Width="*"/>

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition Height="Auto"/>

<RowDefinition Height="*"/>

</Grid.RowDefinitions>

I the lower [left](https://www.mindstick.com/articles/12768/don-t-be-left-behind-with-the-new-it-revolution) cell, i have a [data grid](https://www.mindstick.com/forum/105/what-events-fire-when-binding-data-to-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](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript), and for the [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) to be able to use the datagrid scrollbar to scroll the rows [up and down](https://www.mindstick.com/forum/160255/what-is-the-significance-of-the-up-and-down-methods-in-a-migration-file).

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

ScrollViewer.VerticalScrollBarVisibility="Visible"

of the datagrid, the scrollbar has no [effect](https://yourviews.mindstick.com/view/81363/coronavirus-effect-on-american-farms-is-severe) and the rows flow downwards. Somehow the datagrid does not feel restricted...

What to do?

thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by shreesh chandra shukla

Solution!

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>


---

Original Source: https://www.mindstick.com/forum/1323/how-do-i-make-a-datagrid-fit-the-window-height-in-wpf

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
