No support to remove or modify visual focus style
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
- Run any sample with a button control.
- Press tab key and the default visual focus style will be applied.
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
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.
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
Any update on this? I don't think the workaround that @mattleibow is valid anymore, as it gives a warning
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.