protected void OnPianoKeyPressed(PianoKey key) { if (PianoKeyPressed != null) { PianoKeyPressed(this, new PianoKeyPressedEventArgs(key)); } }
private void DrawKeys() { LayoutRoot.Children.Clear(); double cursorX = 0; for (int pitch = StartingMidiPitch; pitch < StartingMidiPitch + NumberOfKeys; pitch++) { PianoKeyType keyType = KeyTypes[pitch % 12]; double keyHeight = KeyHeight; int zIndex = 0; if (keyType == PianoKeyType.Small) { keyHeight = KeyHeight * 0.6d; zIndex = 10; } PianoKey button = new PianoKey(); button.MidiPitch = pitch; button.Width = keyType == PianoKeyType.Large ? KeyWidth : KeyWidth / 2; button.Height = keyHeight; button.Style = keyType == PianoKeyType.Large ? LargeKeyStyle : SmallKeyStyle; button.Click += button_Click; Canvas.SetLeft(button, pitch > StartingMidiPitch && keyType == PianoKeyType.Small ? cursorX - KeyWidth / 4 : cursorX); Canvas.SetZIndex(button, zIndex); LayoutRoot.Children.Add(button); if (keyType == PianoKeyType.Large) { cursorX += KeyWidth; } } }
void button_Click(object sender, RoutedEventArgs e) { PianoKey key = sender as PianoKey; OnPianoKeyPressed(key); if (PianoKeyPressedCommand == null) { return; } if (!PianoKeyPressedCommand.CanExecuteCommand(key)) { return; } PianoKeyPressedCommand.ExecuteCommand(key); }
public PianoKeyPressedEventArgs(PianoKey key) { Key = key; }