protected void ButtonImage_PreviewMouseDown(object sender, MouseButtonEventArgs e) { try { if (SelectedButtonName == EnumStreamDeckButtonNames.BUTTON0_NO_BUTTON) { return; } var newlySelectedImage = (StreamDeckImage)sender; /* * Here we must check if event if we can change the button that is selected. If there are unsaved configurations we can't */ if (newlySelectedImage.Bill.Button != StreamDeckPanel.GetInstance(PanelHash).SelectedButton&& EventHandlers.AreThereDirtyListeners(this)) { if (CommonUI.DoDiscardAfterMessage(true, "Discard Changes to " + SelectedButtonName + " ?")) { SetFormState(); } else { e.Handled = true; } } } catch (Exception ex) { Common.ShowErrorMessageBox(ex); } }