Questions tagged [focusmanager]
63 questions
39
votes
18 answers
Can't set focus to a child of UserControl
I have a UserControl which contains a TextBox. When my main window loads I want to set the focus to this textbox so I added Focusable="True" GotFocus="UC_GotFocus" to the UserControls definition and FocusManager.FocusedElement="{Binding…

EightyOne Unite
- 11,665
- 14
- 79
- 105
21
votes
4 answers
How to manage Focus state in Jetpack's Compose
I have a custom composable View (Surface + Text essentially) and I want to change the color of the surface depending on the focus state. The FocusManager#FocusNode is marked internal and I am unaware of any way to achieve this. Is this simply just…

Maurycy
- 3,911
- 8
- 36
- 44
13
votes
2 answers
Setting Focus on a Control Within a ControlTemplate (Part 2)
I'm stumped on what must surely be one of the most common WPF requirements. I've read this question but my implementation of the solution does not work.
Here's the markup for the lookless control:

Chris Ward
- 708
- 7
- 19
12
votes
6 answers
How do you solve this LostFocus/LostKeyboardFocus issue?
Ok, I have a control that has an IsEditing property which for argument's sake has a default template that is normally a text block, but when IsEditing is true, it swaps in a textbox for in-place editing. Now when the control loses focus, if it's…

Mark A. Donohoe
- 28,442
- 25
- 137
- 286
11
votes
4 answers
Change focus to next component in JTable using TAB
JTable's default behavior is changing focus to next cell and I want to force it to move focus to next component (e.g. JTextField) on TAB key pressed.
I overrided isCellEditable method of DefaultTableModel to always return false:
public boolean…

Ariyan
- 14,760
- 31
- 112
- 175
10
votes
1 answer
How can I style a custom control based on if any of its children have focus?
We have a custom canvas which has specialized nodes that behave a lot like a standard MDI application's windows. The desired behavior is that if any of the child controls of the "window" have the focus, then that "window" is said to be active.
Now…

Mark A. Donohoe
- 28,442
- 25
- 137
- 286
8
votes
2 answers
How to set logical focus without giving keyboard focus?
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…

FrenchBear38
- 154
- 1
- 5
7
votes
2 answers
Binding to FocusManager.FocusedElement
I have application with several datagrids and export to excel command, which gets focused datagrid as a command parameter. Is it possible to bind CommandParameter to FocusManager.FocusedElement, or do I have to set them explicity?
Thanks in…

Twelve
- 578
- 7
- 15
6
votes
1 answer
Setting focus in WPF with MVVM
I have Grid with multiple Textboxes. Depending on actions the user might take focus should be changed to one of the textboxes. My current solution uses a string property in the ViewModel and a data trigger in xaml to change focus. It works nicely…

Farawin
- 1,375
- 2
- 14
- 19
5
votes
2 answers
Using Key Bindings with Arrow Keys
I'm creating a game that uses the arrow keys to move a sprite. I've added key bindings for the arrow keys and the letter n, but arrow keys aren't working. Here's my code:
public class MyPanel extends JPanel {
Sprite sprite = new Sprite();
…

Eva
- 4,397
- 5
- 43
- 65
4
votes
3 answers
Controling popup open and close focus
I have a popup which contains multiple elements, a list view, a text box and a button. These are operating fine, and if you use the button to close the popup it works as well, but when i tried to make the popup close when it lost focus, it closed…

TerrorAustralis
- 2,833
- 6
- 32
- 46
4
votes
1 answer
Focus Textbox using FocusManager.FocusedElement issue
I'm trying to set the keyboard focus to a textbox that is included in a stackpanel. When the IsEditMode becomes true i want the textbox to become, by default, focused.
I've tried this code:

artos
- 751
- 1
- 10
- 25
3
votes
2 answers
Setting Focus Does Not Allow Instant Editing
I have a WPF UserControl with a textbox. Here's how the textbox and it's parent control are defined:

Nick Heidke
- 2,787
- 2
- 34
- 58
3
votes
1 answer
Xamly set keyboard focus to an element in DataGridTemplateColumn cell?
I've set stuff in a DataGridTemplateColumn.CellEditing DataTemplate.
I want that when the cell editing loads and shows the template, keyboard-focus should be given to a certain control in the template.
Consider this example, when you go edit mode,…

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632
3
votes
1 answer
How to show programmatically FocusVisualStyle?
Afters attemps I could tell that the FocusVisualStyle is only activated by the keyboard (tab and arrows keys).
Try to make the FocusVisualStyle to be applied after the component is loaded, it is impossible to do, There is an easy way to get around…

J. Lennon
- 3,311
- 4
- 33
- 64