How can I define my own columns in a WPF DataGrid?

前端 未结 1 364
Happy的楠姐
Happy的楠姐 2021-01-12 04:04

I\'ve got an AutoGenerateColumns WPF-DataGrid getting bound in code-behind to LINQ-to-SQL, which works fine.

But when I take off the AutoGenerateC

相关标签:
1条回答
  • 2021-01-12 04:41

    You're trying to put the column directly into the DataGrid (therefore it's trying to put the column in the grid's Items collection and that explains your error). You need to put it inside the Columns collection:

    <toolkit:DataGrid x:Name="TheDataGrid" 
                              CanUserAddRows="False"
                              AlternatingRowBackground="#ffffd"
                              CanUserSortColumns="true"
                              PreviewKeyDown="TheDataGrid_PreviewKeyDown"
                              AutoGenerateColumns="False"
                              RowEditEnding="TheDataGrid_RowEditEnding">
        <toolkit:DataGrid.Columns>        
            <toolkit:DataGridTextColumn Header="Contact Name" Width="SizeToCells"  
                                           Binding="{Binding ContactName}" 
                                           IsReadOnly="False"/>
        </toolkit:DataGrid.Columns>
    </toolkit:DataGrid>
    
    0 讨论(0)
提交回复
热议问题