我使用以下代码,例如,当集合是带有数据的字段,例如我在屏幕上看到的2个项目时,在列表的末尾有2行带有数据和一行空行。
如何省略最后一个空行?该集合只有2个条目。收集项目只有2个条目。
<DataGrid RowHeaderWidth="0" ItemsSource="{Binding Items}" AutoGenerateColumns="False">
<!--<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" />
</DataGrid.Resources>-->
<DataGrid.Columns>
<DataGridTemplateColumn Header="1" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Column1, UpdateSourceTrigger=PropertyChanged}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding Column2}" Header="2" Width="*" />
<DataGridTextColumn Binding="{Binding Column3}" Header="3" Width="*" />
<DataGridTextColumn Binding="{Binding Column4}" Header="4" Width="*" />
<DataGridTextColumn Binding="{Binding Column5}" Header="5" Width="*" />
</DataGrid.Columns>
</DataGrid>
最佳答案
尝试将 CanUserAddRows
设置为false,注册的默认值为true:
<DataGrid Name="MyDataGrid"
CanUserAddRows="False" ... />
引用
MSDN
:When this property is set to true a blank row is displayed at the bottom of the DataGrid. A user can enter a new item into the blank row. Adding a new row adds an item to the ItemsSource.
关于wpf - DataGrid表显示额外的不必要的空行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21660935/