如何在WPF数据网格中启用NewItem占位符 [英] How to enable NewItem Placeholder in WPF data grid

查看:84
本文介绍了如何在WPF数据网格中启用NewItem占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf数据网格,它绑定到一个可观察的集合。
目前我没有NewItemPlaceHolder。
如何启用NewItemPlaceholder(底部的空白行以添加新行)?
这是我声明数据网格的方式:

I have a wpf datagrid which is bound to an observable collection. Currently I don't have the NewItemPlaceHolder. How can I enable NewItemPlaceholder (an empty row in the bottom to add new rows)? Here is how I declared my datagrid:

    <WpfToolkit:DataGrid x:Name="grid"
        ItemsSource="{Binding Path=SampleObservableCollection}" 
        HorizontalScrollBarVisibility="Hidden" SelectionMode="Single"
        CanUserAddRows="True" CanUserDeleteRows="True"
        CanUserResizeRows="False" CanUserSortColumns="False"
        CellEditEnding="grid_CellEditEnding"
        CurrentCellChanged="grid_CurrentCellChanged" 
        AutoGenerateColumns="False"
        RowHeaderWidth="17" RowHeight="25">
        <WpfToolkit:DataGrid.Columns> ...

谢谢

推荐答案

确保集合中对象的类型具有默认构造函数。如果没有,则DataGrid无法为新行创建一个新的。

Make sure that the type of the objects in the collection has a default constructor. If it does not, then the DataGrid isn't able to create a new one for the new row.

另请参见这另一个StackOverflow答案

这篇关于如何在WPF数据网格中启用NewItem占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆