0
我有以下情形:將ICommand綁定到MenuItem並指定快捷方式
具有多個ICommand(RelayCommand)屬性的ViewModel。這些屬性綁定到視圖中的菜單項。一些菜單項應該有一個鍵盤快捷鍵。爲此,我嘗試使用窗口的InputBindings。這工作 - 但我必須手動分配InputGestureText到MenuItem。所以我想那裏有綁定一個ICommand的一個菜單項,並分配一個快捷一種更好的方式...
// ViewModel
class MyViewModel: ViewModelBase {
public ICommand TestCommand {get; set;}
}
// View
<Window...>
<Window.InputBindings>
<KeyBinding Command="{Binding TestCommand}" Key="R" Modifiers="Control" />
</Window.InputBindings>
// ...
<MenuItem Name="MenuItemTest" Command="{Binding TestCommand}"
Header="Test" InputGestureText="Ctrl + R" />
</Window>
這是我想回去的WinForms的時刻之一,沒有更好的辦法:/ – Michael
爲什麼呢?由於在指定的WinForms一個快捷方式菜單項顯示分配的快捷方式 - 和我沒有指定一個文本:)約在缺少給予好評:請不要誤會我的意思,你回答我的問題,我接受你的答案。但是,你只是證實了我這樣做是正確的,有沒有其他辦法,所以你沒有提供一個「解決方案」我的問題。但我會爲你的答案投票... – Michael