【发布时间】:2016-02-17 02:31:35
【问题描述】:
我无法通过 UI 在我的 DataGrid 中添加新行。下面是我的代码。
<DataGrid CanUserAddRows="True" Name="dg" ItemsSource="{Binding list}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Path=.}" Header="Text"/>
<DataGridTextColumn Binding="{Binding Length}" Header="Length"/>
</DataGrid.Columns>
</DataGrid>
list是上面Binding中的字符串列表。通常当我设置CanUserAddRows="True"时,我能够在其他示例中自动在UI 上添加行.
我的财产如下:
public List<string> list { get; set; }
在显示DataGrid 之前,它已被初始化。所以不需要为这个属性实现INotifyPropertyChanged。
有人能解释一下为什么DataGrid 会这样吗?如何实现期望的行为?
【问题讨论】:
-
据我所知,当您绑定 DataGrid 时,您无法手动添加行
-
@Rodolfo 当然可以。
-
@Rodolfo 该示例适用于 DataGridView。此处不适用
标签: c# wpf xaml data-binding datagrid