【发布时间】:2016-04-03 17:01:40
【问题描述】:
我有一个DataGrid,里面有一些记录。我想要的是,当我按下键盘上的 Delete 键时,该行被删除,甚至集合中的记录也被删除。
我认为参数 CanUserDeleteRows 可以解决问题,但它不起作用。当我按删除时,该行消失,但仍保留在集合中。
这是我的DataGrid:
<DataGrid
Name="ProjectsGrid"
ItemsSource="{Binding Path=FilesCollection}"
AutoGenerateColumns="False"
CanUserAddRows="False"
CanUserDeleteRows="True">
<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Use" Binding="{Binding Include}"/>
<DataGridTextColumn Header="Name" Binding="{Binding Path, Converter={StaticResource PathConverter}}"/>
</DataGrid.Columns>
</DataGrid>
这是我的 ViewModel:
namespace Validator.ViewModels
{
class SettingsVm : INotifyPropertyChanged
{
public void ChangeProperty(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
public ObservableCollection<CsprojFile> FilesCollection { get; set;}
public SettingsVM()
{
FilesCollection = new ObservableCollection<CsprojFile>();
}
}
我必须向我的 ViewModel 添加一些事件吗?还是有其他我不知道的方法?
提前致谢。
【问题讨论】: