Items collection must be empty before using ItemSource using custom list

后端 未结 2 979
离开以前
离开以前 2021-01-20 16:06

In my class ResultEntity if I do:

_resultMulti = new List(); 

I see the following error message:

相关标签:
2条回答
  • 2021-01-20 16:37

    You are adding your DataGridTextColumns directly as items of the DataGrid, thus you are setting both the Items and ItemsSource property and you can only use one at the same time. Fix your columns configuration by using the Columns attached property:

    <DataGrid.Columns>
        <DataGridTextColumn Header="Task" IsReadOnly="True" Binding="{Binding TaskName}"/>        
        <DataGridTextColumn Header="ABBC" IsReadOnly="True" Binding="{Binding ABBC.DisplayString}"/>
        <DataGridTextColumn Header="BBCA" IsReadOnly="True" Binding="{Binding BBCA.DisplayString}"/>
        <DataGridTextColumn Header="CCCA" IsReadOnly="True" Binding="{Binding CCCA.DisplayString}"/>
    </DataGrid.Columns>
    
    0 讨论(0)
  • 2021-01-20 16:59

    Just wrap your column definitions with DataGrid.Columns. As you are binding it using ItemsSource you can't put any direct content in the definition. It is considering your columns as items of the grid which can't go with ItemsSource collection.

    0 讨论(0)
提交回复
热议问题