WPF datagrid not showing data after binding it to LINQ join query resu

Dec 3 2020 9:44 AM
I have a data grid in WPF that is populated from LINQ join query as follows:
  1. public IEnumerable<InboxTransaction> GetAllInboxTransactions()  
  2. {  
  3. try  
  4. {  
  5. var result =  
  6. from s in this.InboxContext.Inboxes  
  7. join st in this.InboxContext.Sites  
  8. on s.Trans_Site equals st.Site_Code  
  9. select new InboxTransaction  
  10. (  
  11. s.Trans_Number,  
  12. s.Trans_Date,  
  13. s.Trans_Description,  
  14. st.Site_Description  
  15. );  
  16. return (result);  
  17. }  
  18. catch(Exception e)  
  19. {  
  20. MessageBox.Show("??? ??? ???");  
  21. throw (e);  
  22. }  
When I bind the data grid to this result, data grid is not showing any data:
 
var source = InboxTrans.GetAllInboxTransactions();
InboxGrid.ItemsSource = source;
 
This is the definition of the data grid:
  1. <DataGrid Name="InboxGrid" AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeColumns="True" DataContext="{Binding}" FlowDirection="RightToLeft" ItemsSource="{Binding}" Margin="5,94,42,218" Grid.ColumnSpan="3" Grid.Column="2">  
  2. <DataGrid.Columns>  
  3. <DataGridTextColumn Binding="{Binding Trans_Number}" Header="??? ??????" IsReadOnly="True" Visibility="Visible" />  
  4. <DataGridTextColumn Binding="{Binding Trans_Date}" Header="????? ??????" IsReadOnly="True" Visibility="Visible" />  
  5. <DataGridTextColumn Binding="{Binding Trans_Description}" Header="???? ??????" IsReadOnly="True" Visibility="Visible" />  
  6. <DataGridTextColumn Binding="{Binding Site_Name}" Header="????? ?????? ?????" IsReadOnly="True" Visibility="Visible" />  
  7. <DataGridTemplateColumn>  
  8.  <DataGrid Name="InboxGrid" AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeColumns="True"                  DataContext="{Binding}" FlowDirection="RightToLeft" ItemsSource="{Binding}" Margin="5,94,42,218" Grid.ColumnSpan="3" Grid.Column="2">  
  9. <DataGrid.Columns>  
  10. <DataGridTextColumn Binding="{Binding Trans_Number}" Header="??? ??????" IsReadOnly="True" Visibility="Visible" />  
  11. <DataGridTextColumn Binding="{Binding Trans_Date}" Header="????? ??????" IsReadOnly="True" Visibility="Visible" />  
  12. <DataGridTextColumn Binding="{Binding Trans_Description}" Header="???? ??????" IsReadOnly="True" Visibility="Visible" />  
  13. <DataGridTextColumn Binding="{Binding Site_Name}" Header="????? ?????? ?????" IsReadOnly="True" Visibility="Visible" />  
  14. <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate>  
  15. <DataTemplate>  
  16. <Button x:Name="btnDelete" Click="btnDelete_Click" Content="???" />  
  17. </DataTemplate>  
  18. </DataGridTemplateColumn.CellTemplate>  
  19. </DataGridTemplateColumn>  
  20. </DataGrid.Columns>  
  21. </DataGrid>  

Answers (2)