[Windows] Register focus events for controls that can receive focus #23885
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
I noticed that MAUI registers
GotFocus
andLostFocus
events for all platform views on Windows.However, for MAUI
<Label>
s, I believe it's not really necessary.It seems that
TextBlock
(WinUI 3 type that MAUI'sLabel
is mapped to) can be focusable as it contains this method:However, support for
TabStop
s was removed in #1777 (see also #1646 for reasoning) and MAUI does not support text selection forLabel
s.Performance impact
-> ~ 96% improvement
Issues Fixed
Contributes to #21787
Alternative approaches
There is
FocusManager
in WinUI and it has similar events ( https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.input.focusmanager?view=windows-app-sdk-1.5#events), so instead of registering events on all views one by one (and unregistering for that matter). One can probably subscribeFocusManager
events once and just check if the platform view corresponds to one in a dictionary and do the action.