BloggerAds廣告

2021年1月29日 星期五

[C#] WPD : How to make a hot key for application

在WPF的程式裡, 想要加入快捷鍵的功能
首先在Resources中建立Command的名稱, 這部份用來連結CommandBindings和InputBindings
<Window.Resources>
	<RoutedUICommand x:Key="OpenFile" Text="Open File"/>
</Window.Resources>
接下來設定CommandBindings
其中CommandBinding_Executed是執行的Function名稱
<Window.CommandBindings>
	<CommandBinding Command="{StaticResource OpenFile}" Executed="CommandBinding_Executed"/>
</Window.CommandBindings>
最後設定InputBindings
<Window.InputBindings>
	<KeyBinding Key="O" Modifiers="Ctrl" Command="{StaticResource OpenFile}"/>
</Window.InputBindings>

沒有留言:

張貼留言