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; }
}
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:
Changing it to this:
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:
MainWindow.xaml:
Output: