I'm trying to fill a DataGrid
with an anonymous type generated by a LINQ query. When I put the query results in a list box, it appears fine. However, when I put the query results in a data grid, the correct number of rows are generated, but the cells are empty.
(The data grid is on the left, with the list box on the right.)
Assigning the data source:
testListBox.ItemsSource = debtPerUser.ItemsSource = ExpenseViewModel.getDebtData(username);
The XAML:
<sdk:DataGrid Height="222" HorizontalAlignment="Left" Margin="31,89,0,0" Name="debtPerUser" VerticalAlignment="Top" Width="516" AutoGenerateColumns="True" />
<ListBox Height="222" HorizontalAlignment="Left" Margin="567,89,0,0" Name="testListBox" VerticalAlignment="Top" Width="173" />
What could I be doing wrong here?
getDebtData:
internal static IEnumerable getDebtData(string username)
{
IEnumerable<String> users = getUsersInvolving(username);
var debt = from user in users
select new {
User = user,
Net = owedBetween(username, user) - owedBetween(user, username)
};
return debt.Where(d => d.Net != 0);
}
Update: It works when I'm not using an anonymous query type. Perhaps that's the problem?