Tutorial :Simple WPF 4 Question: DataGrid of List of Objects is showing no records



Question:

This is driving me nuts. I have a datagrid in WPF that is not populating with records at runtime.

Here is the XAML. I've done this before in Silverlight although I am a newbie and can't quite figure out what is missing.

<DataGrid AutoGenerateColumns="True" Height="335" HorizontalAlignment="Left" Name="DataGrid1" VerticalAlignment="Top" Width="753">          <DataGrid.Columns>              <DataGridTextColumn Header="Date" Width="175" Binding="{Binding DateTimePosted}"/>              <DataGridTextColumn Header="Name" Width="275"  Binding="{Binding Name}"/>              <DataGridTextColumn Header="Debit" Width="100"  Binding="{Binding DebitAmout}" />              <DataGridTextColumn Header="Credit" Width="100"  Binding="{Binding CreditAmount}" />              <DataGridTextColumn Header="Balance" Width="100"  Binding="{Binding Balance}" />          </DataGrid.Columns>      </DataGrid>  

In code in the loading event I do the following.

DataGrid1.DataContext = Facade.GetTransactions

this returns a list of TransactionItems (custom object) that have public properties matching the fields I am binding in the datagrid XAML.

I've checked and ensured 74 records are being returned.

The grid is still showing up as blank. I'm going bonkers as I can't find an example that is showing me what I can do to correct this.

WPF 4.

I've tried AutoGenerateColumns = True and = False... no diff

Advice


Solution:1

I think you need to use the ItemsSource property, not the DataContext property.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »