开发者

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

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="开发者_StackOverflow社区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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜