From ccb264afe5240f0c6a96617a048fb93139776454 Mon Sep 17 00:00:00 2001 From: Joan Magnet Date: Wed, 28 Aug 2024 17:42:23 +0200 Subject: [PATCH] feat: Change background when Key is pressed --- src/UnoKeyboard/Controls/KeyControl.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/UnoKeyboard/Controls/KeyControl.cs b/src/UnoKeyboard/Controls/KeyControl.cs index d51ddea..c9e715b 100644 --- a/src/UnoKeyboard/Controls/KeyControl.cs +++ b/src/UnoKeyboard/Controls/KeyControl.cs @@ -71,8 +71,27 @@ public KeyControl(KeyboardControl keyboard) Mode = BindingMode.OneWay, }); + // Change key background when the key is pressed + this.PointerPressed += (s, e) => + { + //ControlBorder.Background = new SolidColorBrush(Colors.DimGray); + if (ControlBorder.Background is SolidColorBrush originalBrush) + { + // Obtener el color original + var originalColor = originalBrush.Color; + + // Modificar el canal alfa, por ejemplo, al 50% + var newColor = Windows.UI.Color.FromArgb(50, originalColor.R, originalColor.G, originalColor.B); + + // Aplicar el nuevo color al fondo + ControlBorder.Background = new SolidColorBrush(newColor); + } + }; + this.PointerReleased += (s, e) => { + ControlBorder.Background = Keyboard.KeyBackground; + e.Handled = true; KeyPressed?.Invoke(this, new KeyEventArgs(Key, IsShiftActive));