WPF 数据网格:缺少空白行 [英] 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 数据网格:缺少空白行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!