KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How can I in code define the logical focus of a container, or focused child, WITHOUT giving it keyboard focus ? I just want to control which child will get the focus when the control will get focus through Tab key or clicking on part of the container that does not hit a child, but not give it (or steal) actual focus if it doesn't already have it. And I also want that selecting a specific child through a keyboard gesture or clicking on it with the mouse is still possible. I understand the difference in WPF between Keyboard Focus and Logical Focus, and the fact that for an element, having Keyboard Focus implies also having logical focus, but having logical focus does not imply that the element have keyboard focus. I also understand attached property FocusManager.FocusedElement defines which element has logical focus in the visual tree starting at the element defining this property. I’ve realized that this property is not used only when FocusManager.IsFocusScope is set to true, but also for containers such as GroupBox . I’ve made many attempts, tons of searches and reading on WPF focus topic, but with no success so far, I don't understand what I'm missing: Calling FocusManager.SetFocusedElement also give keyboard focus, and it I temporarily change the property Focusable of my child element to false just before, it only works the very first time when no child had focus before, but not after a child got focus Handling events GotKeyboardFocus and PreviewGotKeyboardFocus at element or container to override initial focused element doesn’t work either, since I cannot tell whether the focus was obtained through the mouse or the keyboard, and whether focus got directly set to a child element or indirectly through the container. An example to illustrate what I’m trying to achieve: I’ve a simple group of RadioButtons,
Tags (comma-separated)
Save Edits
Cancel