WPF DataGrid:空行缺失 [英] WPF DataGrid: Blank Row Missing
问题描述
我正在使用 DataGrid
创建一个WPF窗口,我想显示网格底部的空白新项目行,允许我添加一个新项目到网格。由于某些原因,空白行不会显示在我的窗口上的网格上。以下是我用来创建 DataGrid
的标记:
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>
我不知道为什么空白行不显示。我已经尝试了明显的东西( IsReadOnly =false
, CanUserAddRows =True
),没有运气。任何想法为什么空白行被禁用?感谢您的帮助。
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.
推荐答案
Vincent Sibal发布了一个文章描述添加新行到DataGrid需要什么。有很多可能性,大部分取决于您使用的集合类型 SelectedProject.Tasks
。
Vincent Sibal posted an article describing what is required for adding new rows to a DataGrid. There are quite a few possibilities, and most of this depends on the type of collection you're using for SelectedProject.Tasks
.
我建议确保任务不是只读集合,并且它支持所需的接口之一(在上一个链接中提到),以允许使用DataGrid正确添加新项。
I would recommend making sure that "Tasks" is not a read only collection, and that it supports one of the required interfaces (mentioned in the previous link) to allow new items to be added correctly with DataGrid.
这篇关于WPF DataGrid:空行缺失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!