правка фокуса

main
Stepan Pilipenko 3 weeks ago
parent a7cbcd821e
commit 4a352df139

@ -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<Button, CustomButtonHandler>();
});
#endif
builder.Services.AddSingleton<IFileSystemService, FileSystemService>();
return builder.Build();

@ -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 = @"
<ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
TargetType='Button'>
<Grid x:Name='RootGrid'
Background='{TemplateBinding Background}'
BorderBrush='{TemplateBinding BorderBrush}'
BorderThickness='{TemplateBinding BorderThickness}'>
<ContentPresenter
x:Name='ContentPresenter'
Content='{TemplateBinding Content}'
ContentTemplate='{TemplateBinding ContentTemplate}'
Margin='{TemplateBinding Padding}'
HorizontalAlignment='{TemplateBinding HorizontalContentAlignment}'
VerticalAlignment='{TemplateBinding VerticalContentAlignment}'/>
</Grid>
</ControlTemplate>";
return (Microsoft.UI.Xaml.Controls.ControlTemplate)XamlReader.Load(xaml);
}
}
}
#endif
Loading…
Cancel
Save