void KListener_KeyUp(object sender, RawKeyEventArgs args) { var key = args.Key.ToString(); foreach (BaseKey item in (MainWindow as MainWindow).KeysPanel.Children.OfType <BaseKey>().ToList()) { if (item.Name == key) { (MainWindow as MainWindow).KeysPanel.Children.Remove(item); } } }
void KListener_KeyDown(object sender, RawKeyEventArgs args) { var key = args.Key.ToString(); var visual = SetKeyArt(key); foreach (BaseKey item in (MainWindow as MainWindow).KeysPanel.Children.OfType <BaseKey>().ToList()) { if (item.Name == key) { return; } } (MainWindow as MainWindow).KeysPanel.Children.Add(visual); }