2012-07-17 40 views
0

我有自定義命令ViewModel.DeleteItems。 ViewModel作爲DataContext用於DataGrid。 DeleteItems綁定到上下文菜單並正常工作。綁定CommandBinding到其他命令

我想通過鍵盤「Del」調用這個命令。 我可以使用

<CommandBinding Command="ApplicationCommands.Delete" ... /> 

,但我想ApplicationCOmmands.Delete命令綁定到我的命令,而不硬編碼(我並不想訂閱的CommandBinding.Executed和手動運行DeleteItems)。如何將應用程序命令綁定到我的自定義命令只有datagrid?

回答

0

時的「Del」鍵被按下時,您應該能夠使用一個按鍵綁定火了你的命令,如:

<DataGrid.InputBindings> 
    <KeyBinding Key="Del" Command="{Binding DeleteItems}" /> 
</DataGrid.InputBindings> 

你不應該需要ApplicationCommands.Delete做任何事情來得到這個行爲。