Detecting the user pressing F10 in WPF Detecting the user pressing F10 in WPF wpf wpf

Detecting the user pressing F10 in WPF


In addition to Yacoder's response, use the following to check for the F10 key:

case Key.System:  if (e.SystemKey == Key.F10)  {    // logic...  }

The SystemKey property will tell you which System key was pressed.


Answer with DataContext:

    public partial class BankView : UserControl    {        public BankView()        {            InitializeComponent();            this.KeyDown += new KeyEventHandler(BankView_KeyDown);        }         private void BankView_KeyDown(object sender, KeyEventArgs e)        {            try            {                switch (e.Key)                {                    case Key.F4:                        ((BankViewModel)DataContext).OpenAccount();                        break;                }            }            catch (Exception ex)            {                ...            }        }