Techno Live

Techno Live

  • NA
  • 16
  • 5.7k

Hotkey on user control WPF c#

Jun 8 2018 10:56 AM

my project it:

- one windows (Access.xaml)

- other page is redirect (User Control) Internal (my windows).

  1. _toolbarcontent.Visibility = Visibility.Visible;
  2. 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).

  1. private void _addHotKeys() { 
  2. HotkeyManager.Current.AddOrReplace("Pay", Key.F1, ModifierKeys.None, PayHotKey);
  3. HotkeyManager.Current.AddOrReplace("sel", Key.F2, ModifierKeys.None, SelHotKey);
  4. }

  5. private void PayHotKey(object sender, EventArgs e)
  6. {
  7.  Properties.Settings.Default.ParaMID = "35";
  8.  Properties.Settings.Default.Save();
  9.  _libcode.HideForm();
  10. }

  11. private void SelHotKey(object sender, EventArgs e)
  12. {
  13.  Properties.Settings.Default.ParaMID = "45";
  14.  Properties.Settings.Default.Save();
  15.  _libcode.HideForm();
  16. } 
this code is successful but appeared in exception error code (Already Register Hot key like
  1. HotkeyManager.Current.AddOrReplace("Exit", Key.Escape, ModifierKeys.None, ExitHotKey); 
- KeyDown, PreviewKeyDown ON User Control OR Main Grid, but not fired on Escape Key to hide user control appeared.
  1. 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:

  1. private void root_KeyDown(object sender, KeyEventArgs e)
  2. if (e.Key == Key.Escape)
  3.      {
  4.      _resultDiag = false;
  5.      HideHandlerDialog();
  6.      }

Please Help Me, I want To Library OF Hot Key Management With Option and Most controlled like check if register and controlled if exist.. etc AND Applied ON (USER CONTROL) WPF with C# NOT ON Windows WPF C#.

Answers (1)