-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: Focus scope API no longer accessible #11613
Comments
I could provide a PR, however, I don't want to interfere with any ongoing focus manager work. (Also, I am open for alternative solutions.) |
They can, but you are right - there are no focus scopes in public API anymore.
There is a high chance of removing custom focus scopes (i.e. implementation of IFocusScope), as there is no WPF/UWP. FocusManager.IsFocusScope="True" is a possible alternative though.
While generally, TopLevel has aspects of IFocusScope, I don't see how it can be used on Menu. But I guess I am missing some points about routed commands.
I expect it should be triggered from the currently focused element up to the visual tree. Am I wrong?
So, do I understand it correctly, you record focus scope on menu navigation, save it, and use it when any nested command is raised which should propagate from the upper focus scope up the tree? |
Either way, it doesn't sound like something that can't be done with existing API without making it more complex:
But I might be missing something as well. |
True, using Just to clarify the questions above:
Say you have a
That's generally how the routed commands work in WPF and in my Avalonia app.
Yes, except that currently I don't have to manually record anything. The Avalonia |
Closing the issue for now. Will open another issue if I hit any blockers. |
IIRC there were hard to resolve issues with the way focus scopes are implemented. There are some plans to have a full WPF-like implementation, but no ETA yet. |
No worries, I am making headway using my own implementation – manually tracking focus and focus scopes as @maxkatz6 suggested. |
Describe the bug
The focus scope API (
FocusManager.Scope
,FocusManager.GetFocusedElement(IFocusScope)
) is no longer accessible as of #11407, which is breaking our app/UI libraries.Our current app implements
ToolBar
s,RoutedCommand
s (similar to WPF), a "Quick Launch Box"/"Command palette" and docking windows (like Visual Studio). The application depends on focus scopes. Details:Window
s,Menu
s,ToolBarTray
s and the "Quick Launch Box" implementIFocusScope
.FocusManager
keeps track of the last focused element in each focus scope.RoutedCommand
s. Similar to WPF's ApplicationCommands.Menu
,ToolBar
, or "Quick Launch Box" is triggered it needs to be routed to the previously focused element. This is done by determining the current focus scope (FocusManager.Scope
), finding the parent focus scope, and routing the event to the last focused element (FocusManager.GetFocusedElement(IFocusScope)
).To Reproduce
Third-party apps or UI control libraries can no longer access
FocusManager
. The focus scope API is not exposed inIFocusManager
.Expected behavior
Third-party apps or UI control libraries should have a way to access focus scopes.
Solution
This can be solved by pulling the following members from
FocusManager
intoIFocusManager
:Focus scopes are an important concept needed for command routing in complex scenarios and for porting WPF applications to Avalonia UI. I strongly recommend keeping the functionality and not removing it as part of any future changes (e.g. #7607).
Screenshots
n.a.
Desktop (please complete the following information):
Additional context
n.a.
The text was updated successfully, but these errors were encountered: