WPF DataGrid ObservableCollection绑定 - 带有空集合的5行

时间:2015-11-21 17:41:27

标签: c# wpf datagrid observablecollection

我正在尝试将ObservableCollection绑定到我的DataGrid。该集合为空,但DataGrid显示5个空行。关于会导致这种情况的任何想法?

<DataGrid AutoGenerateColumns="true" Name="dgBills" Grid.Row="0" Margin="10, 10, 10, 5" Background="DarkRed" ItemsSource="{Binding Source=Bills}">

        <DataGrid.Resources>
            <Style TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="Background" Value="Red" />
                <Setter Property="Foreground" Value="White" />
                <Setter Property="FontSize" Value="20" />
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </DataGrid.Resources>

        <DataGrid.Columns>
            <DataGridTextColumn Header="Date" Width="1*" Binding="{Binding NextDueDate}" />
            <DataGridTextColumn Header="Desc" Width="1*" Binding="{Binding Description}" />
            <DataGridTextColumn Header="Amount" Width="1*" Binding="{Binding Amount}" />
            <DataGridTextColumn Header="Frequency" Width="1*" Binding="{Binding Frequency}" />
        </DataGrid.Columns>

</DataGrid>

enter image description here

1 个答案:

答案 0 :(得分:0)

我添加了C#

dgBills.ItemsSource = Bills;

修复它的whala。

enter image description here