DataGrid不显示,ListView工作正常吗?

时间:2011-09-15 16:57:43

标签: wpf xaml binding datagrid

想想我在这里错过了一些非常简单的东西,但我似乎无法让我的Datagrid正确显示?

我最初使用ListView来显示一些表格数据,但我想自动调整列,所以我使用DataGridTextColumns切换到DataGrid,现在我什么都没得到。网格中显示正确的行数,但每个单元格显示为空白。有什么想法吗?

这是我的XAML:

<DataGrid ItemsSource="{Binding Charges}" AutoGenerateColumns="True">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Count" Binding="{Binding Count, Mode=OneWay}" Width="SizeToCells" />
        <DataGridTextColumn Header="Charge" Binding="{Binding LawId, Mode=OneWay, Converter={StaticResource LawConverter}}" Width="SizeToCells" />
        <DataGridTextColumn Header="Incident Date" Binding="{Binding IncidentDate, Mode=OneWay, Converter={StaticResource DateConverter}}" Width="SizeToCells" />
        <DataGridCheckBoxColumn Header="Convicted" Binding="{Binding IsConvicted, Mode=OneWay}" />
        <DataGridTextColumn Header="Disposition" Binding="{Binding ChargeDispositionCodeId, Mode=OneWay, Converter={StaticResource CodeConverter}, ConverterParameter='ChargeDispositionCode'}" Width="SizeToCells" />
        <DataGridTextColumn Header="Disposition Date" Binding="{Binding DispositionDate, Mode=OneWay, Converter={StaticResource DateConverter}}" Width="SizeToCells" />
    </DataGrid.Columns>
</DataGrid>

其他信息:
这个xaml DOES可以正常工作和显示,但我希望这些列可以自动调整大小,因此DataGrid会更好:

<ListView ItemsSource="{Binding Charges}">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Count" DisplayMemberBinding="{Binding Count, Mode=OneWay}" />
            <GridViewColumn Header="Charge" DisplayMemberBinding="{Binding LawId, Mode=OneWay, Converter={StaticResource LawConverter}}" />
            <GridViewColumn Header="Incident Date" DisplayMemberBinding="{Binding IncidentDate, Mode=OneWay, Converter={StaticResource DateConverter}}" />
            <GridViewColumn Header="Convicted" DisplayMemberBinding="{Binding IsConvicted, Mode=OneWay}" />
            <GridViewColumn Header="Disposition" DisplayMemberBinding="{Binding ChargeDispositionCodeId, Mode=OneWay, Converter={StaticResource CodeConverter}, ConverterParameter='ChargeDispositionCode'}" />
            <GridViewColumn Header="Disposition Date" DisplayMemberBinding="{Binding DispositionDate, Mode=OneWay, Converter={StaticResource DateConverter}}" />
        </GridView>
    </ListView.View>
</ListView>

1 个答案:

答案 0 :(得分:0)

初始化网格时检查输出调试器窗口。你收到任何Binding错误信息吗?

您还需要关闭“AutoGenerateColumns”,因为您明确定义了XAML中的列。