From 4a352df139242da5b3f34a517fa755071d0af765 Mon Sep 17 00:00:00 2001 From: Stepan Pilipenko Date: Sat, 22 Nov 2025 15:38:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D1=84?= =?UTF-8?q?=D0=BE=D0=BA=D1=83=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MauiProgram.cs | 11 ++++ Platforms/Windows/CustomButtonHandler.cs | 64 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 Platforms/Windows/CustomButtonHandler.cs diff --git a/MauiProgram.cs b/MauiProgram.cs index 5aaf904..e2dc03f 100644 --- a/MauiProgram.cs +++ b/MauiProgram.cs @@ -1,5 +1,9 @@ using Microsoft.Extensions.Logging; +#if WINDOWS +using CommanderApp.Platforms.Windows.Handlers; +#endif + namespace CommanderApp { public static class MauiProgram @@ -17,6 +21,13 @@ namespace CommanderApp #if DEBUG builder.Logging.AddDebug(); +#endif +#if WINDOWS + // Регистрируем кастомный handler для кнопок + builder.ConfigureMauiHandlers(handlers => + { + handlers.AddHandler(); + }); #endif builder.Services.AddSingleton(); return builder.Build(); diff --git a/Platforms/Windows/CustomButtonHandler.cs b/Platforms/Windows/CustomButtonHandler.cs new file mode 100644 index 0000000..2da6c81 --- /dev/null +++ b/Platforms/Windows/CustomButtonHandler.cs @@ -0,0 +1,64 @@ +#if WINDOWS +using Microsoft.Maui.Handlers; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Markup; + +namespace CommanderApp.Platforms.Windows.Handlers +{ + public partial class CustomButtonHandler : ButtonHandler + { + protected override void ConnectHandler(Microsoft.UI.Xaml.Controls.Button platformView) + { + base.ConnectHandler(platformView); + ConfigureButton(platformView); + } + + private static void ConfigureButton(Microsoft.UI.Xaml.Controls.Button button) + { + // Полностью отключаем все системные визуалы + button.UseSystemFocusVisuals = false; + + var transparentBrush = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent); + + button.FocusVisualPrimaryBrush = transparentBrush; + button.FocusVisualSecondaryBrush = transparentBrush; + button.FocusVisualPrimaryThickness = new Microsoft.UI.Xaml.Thickness(0); + button.FocusVisualSecondaryThickness = new Microsoft.UI.Xaml.Thickness(0); + + button.AllowFocusOnInteraction = true; + button.IsTabStop = true; + + // Отключаем переходы + button.Transitions = null; + + // Создаем минимальный Template + button.Template = CreateMinimalTemplate(); + } + + private static Microsoft.UI.Xaml.Controls.ControlTemplate CreateMinimalTemplate() + { + // Минимальный ControlTemplate без VisualStateManager + var xaml = @" + + + + +"; + + return (Microsoft.UI.Xaml.Controls.ControlTemplate)XamlReader.Load(xaml); + } + } +} +#endif \ No newline at end of file