dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.96k stars 1.7k forks source link

No support to remove or modify visual focus style #10193

Open karthikraja-arumugam opened 1 year ago

karthikraja-arumugam commented 1 year ago

Description

The visual focus style is applied to controls in Tab key press on windows platform. But there is no support to remove or modify this focus style.

Focus style is not applied on MacCatalyst. so in our control, we handle this style locally on tab key press but in the windows platform, we cannot change this style.

In native WinUI platform, we can restrict this using IsTabStop and usesystemfocusvisuals API's.

Steps to Reproduce

  1. Run any sample with a button control.
  2. Press tab key and the default visual focus style will be applied.
Screenshot 2022-09-18 200314

Link to public reproduction project repository

https://github.com/KarthikRajaAKR/Samples/tree/main/VisualFocus

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Windows SDK 10.0.19041

Did you find any workaround?

No

Relevant log output

No response

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mattleibow commented 1 year ago

Until we add some new APIs, you can add custom property to the view handlers on windows.

Pseudocode:

#if WINDOWS
ViewHandler.ViewMapper["UseSystemFocusVisuals"] = (handler, platformView) => {
    if (platformView is Control ctrl)
        ctrl.UseSystemFocusVisuals = false;
}
#endif
daltzctr commented 1 year ago

Any update on this? I don't think the workaround that @mattleibow is valid anymore, as it gives a warning

MartyIX commented 7 months ago

Possible workaround for Buttons on Windows:

// See https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.control.usesystemfocusvisuals.
Microsoft.Maui.Handlers.ButtonHandler.Mapper.AppendToMapping("Project.Buttons.NoSystemFocus", (Microsoft.Maui.Handlers.IButtonHandler handler, IButton view) =>
{
    if (view is Button)
    {
        handler.PlatformView.UseSystemFocusVisuals = false;
    }
});

Possible workaround for Pickers on Windows:

// See https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.control.usesystemfocusvisuals.
Microsoft.Maui.Handlers.PickerHandler.Mapper.AppendToMapping("Project.Pickers.NoSystemFocus", (Microsoft.Maui.Handlers.IPickerHandler handler, IPicker view) =>
{
    if (view is not Picker)
        return;

    if (handler.PlatformView is not Microsoft.UI.Xaml.Controls.ComboBox comboBox)
        return;

    comboBox.UseSystemFocusVisuals = false; // This does not seem to be enough as for buttons above.
    comboBox.IsTabStop = false; // This seems to do the trick for pickers on Windows but it has obvious issue.
});

Take it with a grain of salt. Ideas for improvements are welcome.