Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:07:20+00:00 2026-06-05T18:07:20+00:00

I have a WPF DataGrid that increases in height when I add data to

  • 0

I have a WPF DataGrid that increases in height when I add data to it that won’t fit inside its initial height. I don’t want the height to change unless the user increases the Window size. Is there a way to stop this auto-resize?

<Window x:Class="WpfDataGridSizeTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Loaded="Window_Loaded"
        SizeToContent="WidthAndHeight">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <DockPanel Grid.Row="0">
            <DataGrid x:Name="wordsDataGrid" VerticalAlignment="Top" ItemsSource="{Binding}" MinHeight="100" SelectionMode="Single" AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto" >
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Column" Width="Auto" Binding="{Binding AString}"/>
                </DataGrid.Columns>
            </DataGrid>
        </DockPanel>
    </Grid>
</Window>

    public partial class MainWindow : Window
    {
        MyList myList = new MyList();

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            wordsDataGrid.DataContext = myList;
            for (int i = 0; i < 100; ++i)
            {
                myList.AddOne("blah blah");
            }
        }
    }

    public class MyList : ObservableCollection<AClass>
    {
        public MyList() { }

        public void AddOne(string aString)
        {
            base.Add(new AClass(aString));
        }
    }

    public class AClass
    {
        public string AString { get; set; }

        public AClass(string aString)
        {
            AString = aString;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:07:22+00:00Added an answer on June 5, 2026 at 6:07 pm

    If I don’t get you wrong, you want your DataGrid to be in centain Height initally, with some Empty Space below the DataGrid within the Windows…Then when resize the Window, the DataGrid will changes it size.

    Add one more Row to the Grid, and define a MinHeight of that Row. Then set DataGrid to be VerticalAlignment = Stretch. Also set a default height size for the Window.

    <Window x:Class="WpfDataGridSizeTest.MainWindow" 
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
            Title="MainWindow" Loaded="Window_Loaded" Height="300"> 
        <Grid> 
            <Grid.RowDefinitions> 
                <RowDefinition Height="*"/> 
                <RowDefinition MinHeight="100"/> 
            </Grid.RowDefinitions> 
            <DockPanel Grid.Row="0" VerticalAlignment="Stretch"> 
                <DataGrid x:Name="wordsDataGrid" VerticalAlignment="Stretch" ItemsSource="{Binding}" MinHeight="100" SelectionMode="Single" AutoGenerateColumns="False" VerticalScrollBarVisibility="Auto" > 
                    <DataGrid.Columns> 
                        <DataGridTextColumn Header="Column" Width="Auto" Binding="{Binding AString}"/> 
                    </DataGrid.Columns> 
                </DataGrid> 
            </DockPanel> 
        </Grid> 
    </Window> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF DataGrid that I want to be able to Update, Insert
I have a wpf datagrid (.NET 4.0) that contains raw data from a database,
I want to achieve the following: Create a WPF DataGrid that have 2 columns:
I have a WPF DataGrid that will be populated from a data table having
I have a WPF DataGrid with some data. You can add rows through a
I have a WPF DataGrid that in its first column holds a number that
I have a WPF datagrid that is filled with an ObserverableCollection. Now I want
I have a WPF DataGrid that I load with data from a SQL db.
I have a WPF DataGrid which has a DataTable as its ItemsSource . The
I have a WPF DataGrid who's data source is an ObservableCollection. It is set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.