Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

WPF DataGrid: Blank Row Missing

I am creating a WPF window with a DataGrid, and I want to show the blank "new item" row at the bottom of the grid that allows me to add a new item to the grid. For some reason, the blank row is not shown on the grid on my window. Here is the markup I used to create the DataGrid:

<toolkit:DataGrid  x:Name="ProjectTasksDataGrid" 
                   DockPanel.Dock="Top" 
                   Style="{DynamicResource {x:Static res:SharedResources.FsBlueGridKey}}"
                   AutoGenerateColumns="False" 
                   ItemsSource="{Binding SelectedProject.Tasks}" 
                   RowHeaderWidth="0" 
                   MouseMove="OnStartDrag" 
                   DragEnter="OnCheckDropTarget" 
                   DragOver="OnCheckDropTarget" 
                   DragLeave="OnCheckDropTarget" 
                   Drop="OnDrop" 
                   InitializingNewItem="ProjectTasksDataGrid_InitializingNewItem">
    <toolkit:DataGrid.Columns>
        <toolkit:DataGridCheckBoxColumn HeaderTemplate="{DynamicResource {x:Static res:SharedResources.CheckmarkHeaderKey}}" Width="25" Binding="{Binding Completed}" IsReadOnly="false"/>
        <toolkit:DataGridTextColumn Header="Days" Width="75" Binding="{Binding NumDays}" IsReadOnly="false"/>
        <toolkit:DataGridTextColumn Header="Due Date" Width="75" Binding="{Binding DueDate, Converter={StaticResource standardDateConverter}}" IsReadOnly="false"/>
        <toolkit:DataGridTextColumn Header="Description" Width="*" Binding="{Binding Description}" IsReadOnly="false"/>
    </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

I can't figure out why the blank row isn't showing. I have tried the obvious stuff (IsReadOnly="false", CanUserAddRows="True"), with no luck. Any idea why the blank row is disabled? Thanks for your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You must also have to have a default constructor on the type in the collection.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...