Home > DeveloperSection > Forums > how do I make a datagrid fit the window height in wpf?
Takeshi Okada
Takeshi Okada

Total Post:89

Points:629
Posted on    July-18-2013 11:36 PM

 WPF WPF 
Ratings:


 1 Reply(s)
 3252  View(s)
Rate this:
Hi developers!

I have a grid with 3 columns and 2 rows

        <Grid.ColumnDefinitions>

            <ColumnDefinition Width="Auto"/>

            <ColumnDefinition Width="10"/>

            <ColumnDefinition Width="*"/>

        </Grid.ColumnDefinitions>

        <Grid.RowDefinitions>

            <RowDefinition Height="Auto"/>

            <RowDefinition Height="*"/>

        </Grid.RowDefinitions>

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

ScrollViewer.VerticalScrollBarVisibility="Visible"

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



shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Points:735
Posted on    July-19-2013 12:21 AM

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>


Don't want to miss updates? Please click the below button!

Follow MindStick