Ejemplo n.º 1
0
        private void ListViewItem_KeyDown(object sender, KeyEventArgs e)
        {
            //switch (e.Key)
            //{
            //    case Key.Left:
            //    case Key.Right:
            //    case Key.Up:
            //    case Key.Down:
            //    case Key.S:
            //    case Key.D0:
            //    case Key.D1:
            //    case Key.D2:
            //    case Key.D3:
            //    case Key.D4:
            //    case Key.D5:
            //    case Key.D6:
            //    case Key.D7:
            //    case Key.D8:
            //    case Key.D9:

            //        e.Handled = true;
            //        break;
            //    default:
            //        break;
            //}
            e.Handled = true;
            Regex key = new Regex(@"\w");
            Sound z   = ListOfSounds.SelectedItem as Sound;

            if (e.Key == Key.Enter && z != null)
            {
                SoundVM.Play(z);
            }
            else if (key.IsMatch(e.Key.ToString()) && e.Key != Key.System)
            {
                var strKey = new KeyConverter().ConvertToString(e.Key);
                if (strKey.Length > 1)
                {
                    strKey = strKey.Replace("NumPad", "").Replace("D", "");
                }
                s = SoundVM.Sounds.FirstOrDefault(a => a.Name[0].ToString().ToUpper() == strKey.ToUpper());
                ListOfSounds.SelectedItem = s;
                ListOfSounds.ScrollIntoView(ListOfSounds.SelectedItem);
            }
        }
Ejemplo n.º 2
0
        private void Number_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                this.Close();
            }
            else if (e.Key == Key.Escape)
            {
                txtnumber.Password = "";
                this.Close();
            }
            else if (e.Key == Key.Back)
            {
                txtnumber.Password = txtnumber.Password.Length == 0 ? "" : txtnumber.Password.Remove(txtnumber.Password.Length - 1);
            }
            else
            {
                Regex R = new Regex("[0-9]");

                var strKey = new KeyConverter().ConvertToString(e.Key);
                if (strKey.Length > 1)
                {
                    strKey = strKey.Replace("NumPad", "").Replace("D", "");
                }
                if (strKey.Length == 1)
                {
                    if (R.IsMatch(strKey))
                    {
                        txtnumber.Password += strKey;
                    }
                }
                else
                {
                    e.Handled = true;
                }
            }
        }