I’m populating datagrid with collection of anonymous types (I’m setting DataGrid's DataContext property). And there are no errors. And nothing dsiplayed in datagrid. I’ve tried to make the same with defined object collection, but again nothing is displayed. Please could you instruct me what to do.
Thanks!
EDIT 1
Ok. I tried to set ItemsSource property and it works. But I’m getting strange result..

EDIT 2
I don’t know how but after 3d launch it now’s working properly?
private void ShowABCResultsButtonOnClick(Object sender, RoutedEventArgs e)
{
var anonArray = new List<NormalizedResult>
{
new NormalizedResult
{
Key = 1,
Title = "Колос",
Volume = 1322.01m,
Weighted = 6.7840m,
Result = 6.7840m,
Group = "A"
},
new NormalizedResult
{
Key = 2,
Title = "Украинский Новый",
Volume = 1250.47m,
Weighted = 6.4169m,
Result = 13.2009m,
Group = "A"
},
new NormalizedResult
{
Key = 3,
Title = "Ржано-Пшеничный",
Volume = 1202.1m,
Weighted = 6.1687m,
Result = 19.3695m,
Group = "A"
}
};
this.dataGrid2.ItemsSource = anonArray;
}
this is my code.
And again I’ve launched.. and it displayed properly only the third time?
You likely need to do two things. The first, as @Tim suggested, is assign the query to the
DataGrid.ItemsSourceproperty.The second bit will be to enable automatic column generation on yourDataGrid:Edit: I’ve recreated your picture using automatic column generation and anonymous types with a vanilla LINQ query. So you
will need to becould use explicit columns to use or switch to a real type.Edit 2: You CAN use
AutoGenerateColumns="True"just not with the bareIEnumerable<T>whereTis an anonymous type. By addingToListthe problem goes away.XAML then goes back to: