Fitting WPF DataGrid in a Grid control

Total Post:134


 1439  View(s)
Rate this:

I have a DataGrid control inside a Grid control in one of my WPF windows.

        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
  <SomeControl Grid.Row="0" />
  <DataGrid Grid.Row="1" VerticalScrollBarVisibility="Visible" VerticalAlignment="Stretch"/>

The problem is that when I add rows to the DataGrid it flows out of the containing window and its scroll bar remains inactive. How do I solve this problem and make the DataGrid's scroll bar to function correctly?

  1. Re: Fitting WPF DataGrid in a Grid control

    Hi Tanuj,

    You may try as follows

                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="200" />
                <DataGrid   Grid.Row="1" HorizontalAlignment="Left" Margin="54,65,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="382" VerticalScrollBarVisibility="Visible">
                        <DataGridTextColumn Header="ID"/>
                        <DataGridTextColumn Header="ViewCount" />
                        <DataGridTextColumn Header="Title" />

    You need to provide some height to the DataGrid ,as you have RowDefinition Height="*" so the vertical Scrolbar was not active,try to give some height to the DataGrid.

    Hope it will help you.

      Modified On Mar-31-2018 01:10:12 AM


Please check, If you want to make this post sponsored

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