在Keypress上删除ListView SelectedItem

Dav*_*ave 3 c# wpf listview

我希望按下Delete键以按下DelegateCommand以实际删除此时的selecteditem.

我很难找到正确的语法来做到这一点.我正在使用INotifyPropertyChanged实现绑定到我的ViewModel上的公共propreties.

有没有办法做到这一点?似乎应该有.

我有一个

ObservableCollection<Object> Objects
Run Code Online (Sandbox Code Playgroud)

让我们说每个对象中的字段(即名称,地址)

谢谢你的帮助

emy*_*bob 8

要从按键触发命令:

   <ListView ItemsSource="{Binding Path=Objects}" SelectedItem="{Binding Path=SelectedObject}">
        <ListView.InputBindings>
            <KeyBinding Key="Delete" Command="{Binding Path=MyCommand}"></KeyBinding>
        </ListView.InputBindings>
   </ListView>
Run Code Online (Sandbox Code Playgroud)

对于您选择的项目,在viewModel中有一个属性,并将listView的SelectedItem绑定到它.