my project it:
- one windows (Access.xaml)
- other page is redirect (User Control) Internal (my windows).
- _toolbarcontent.Visibility = Visibility.Visible;
- content.Content = new Pages.xcompany();
Then I Used Quick Lunch On Main page(user control: Welcome.xaml).
I want to use hot key For example (F1 Key: receipt voucher Page, F2 Key.. etc)
I tried Sample Code:
- (NHotKey But I can't Adjustment and this library not content More option like (define global, local.., check if exist already hotkey, exception, ...etc).
- private void _addHotKeys() {
- HotkeyManager.Current.AddOrReplace("Pay", Key.F1, ModifierKeys.None, PayHotKey);
- HotkeyManager.Current.AddOrReplace("sel", Key.F2, ModifierKeys.None, SelHotKey);
- }
- private void PayHotKey(object sender, EventArgs e)
- {
- Properties.Settings.Default.ParaMID = "35";
- Properties.Settings.Default.Save();
- _libcode.HideForm();
- }
- private void SelHotKey(object sender, EventArgs e)
- {
- Properties.Settings.Default.ParaMID = "45";
- Properties.Settings.Default.Save();
- _libcode.HideForm();
- }
- HotkeyManager.Current.AddOrReplace("Exit", Key.Escape, ModifierKeys.None, ExitHotKey);
- x:Class="_main.lDialog" x:Name="root" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" PreviewKeyDown="root_KeyDown">
My Code:
- private void root_KeyDown(object sender, KeyEventArgs e)
- { if (e.Key == Key.Escape)
- {
- _resultDiag = false;
- HideHandlerDialog();
- }
- }
Logesh PalaniPosted Oct 27, 2018, 5:13 AM
I understand the standard way is by creating Commands and then adding your shortcut keys to them as InputGestures. This enables the shortcut keys to work even if they're not hooked up to any controls. And since menu items understand keyboard gestures, they'll automatically display your shortcut key in the menu items text, if you hook that command up to your menu item.
A. Create static attribute to hold command (preferably as property in static class you create for commands - but for simple example, just using static attribute in window .cs):