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 7568999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:04:10+00:00 2026-05-30T15:04:10+00:00

dg.ItemsSource=GetList(); I debug the program and see that ItemSource receives full items but there

  • 0
dg.ItemsSource=GetList();

I debug the program and see that ItemSource receives full items but there is nothing shown in the grid at all.
I also would like to know how can I dock my datagrid control into the WIndows such that it also resizes itself once I resize the parent windows?
Thank you

{UPDATE}

I am wpf new learner. I think using only the source code above can also automatically bind the data source with the specified control. I am not thinking about creating a loop to insert item by item into the grid. I will do this but I need you help me tell me whether what I am thinking is correct.

My datalist is a list of class that contains string items

    public class Author
    {
        public string Name { get; set; }
        public DateTime PostedDate { get; set; }
        public string ProjectTitle { get; set; }
        public string Content { get; set; }
        public string Link { get; set; }
    }
  • 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-05-30T15:04:11+00:00Added an answer on May 30, 2026 at 3:04 pm

    Check the AutoGenerateColumns, Height, Width, HorizontalAlignment and VerticalAlignment properties on the grid. If you just drag-and-drop it from the Toolbox onto your XAML design surface, this code gets generated:

    <DataGrid AutoGenerateColumns="False" Height="200" HorizontalAlignment="Left" Margin="254,64,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="200" />
    

    Changing it to this:

    <DataGrid HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch"/>
    

    should solve both of your problems.

    EDIT: You did not specify what type of elements your list contains, but be aware that the automatically generated columns will be bound to the public properties of your list items.

    EDIT2:
    Now that you added your list item type, here’s a sample:

    MainWindow.xaml.cs:

    public partial class MainWindow: Window
    {
      public MainWindow()
      {
        InitializeComponent();
    
        List<Author> list = new List<Author> 
        {
          new Author { Name = "X Y", Content = "blah" },
          new Author { Name = "W Z", Content = "blah blah" },
          new Author { Name = "N N", Content = "blah blah blah" },
          new Author { Name = "M M", Content = "blah blah blah blah" },
        };
        dataGrid1.AutoGenerateColumns = true;
        dataGrid1.ItemsSource = list;
      }
    }
    
    public class Author
    {
      public string Name { get; set; }
      public DateTime PostedDate { get; set; }
      public string ProjectTitle { get; set; }
      public string Content { get; set; }
      public string Link { get; set; }
    }
    

    MainWindow.xaml:

    <Window x:Class="WpfApplication1.MainWindow"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              Title="MainWindow" Height="350" Width="525">
      <Grid>
         <DataGrid HorizontalAlignment="Stretch" Name="dataGrid1" VerticalAlignment="Stretch"/>
      </Grid>
    </Window>
    

    Output:

    Sample output

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XAML MenuItem DataBound ItemsSource that is working fine however there is
Consider the below if(type== S) { lstItem.ItemsSource = (from item in Items where item.Property1
I binding ItemsSource of TabControl, when I added new TabItem, It is visible but
I need to implement CheckBoxList control with ItemsSource and CheckedItems properties. Items from ItemsSource
The problems is simple: when ItemsSource is updated Combobox doesn't refresh e.g. new items
I have a ComboBox whose ItemsSource is bound to an ObjectDataProvider that has its
I have a ListView that I set it's ItemsSource to list all the Assignments
I have a TabControl in WPF / MVVM that is bound to an ItemsSource
I'm receiving this error: items collection must be empty before using itemssource in a
I have a WPF ListBox that is set to scroll horizontally. The ItemsSource is

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.