What is the “pressed the delete key” event for the WPF Datagrid?

后端 未结 6 896
暗喜
暗喜 2020-12-13 04:16

I want to enable the user to highlight a row on the WPF DataGrid and press delete key to delete the row.

  • the functionality is already
6条回答
  •  醉梦人生
    2020-12-13 04:50

    What are you binding your DataGrid to? Ideally, you should react to CollectionChanged events on the collection you are binding to. That way, your logic (deletion of removed items) will be separated from your UI.

    You can build an Observable collection containing your objects and bind it to ItemsSource just for that purpose if the original collection does not have the necessary events.

    It might not suit your specific setup, but that's how I usually do it.

提交回复
热议问题