On Wpf container tabbing is not loosing focus on button - c#

A button on wpf container is not loosing focus style while tabbing across the windows.The control does go to the other elements but the button will still have the focus style on it.

Does the button have IsDefault=True? This will cause the button to always have keyboard focus for the Enter key as long as another control is not capturing the keyboard input.

Related

WPF Keep textbox focussed while pressing tab key

I am writing a WPF application where we are supposed to shift focus from one button to another by pressing the TAB key.
All is fine, but for a specific page, there is a textbox which is always focused so that the user can type in it immediately. But now, when I press TAB, the focus is shifted to the button (which is as per requirement) but as the focus is lost from the textbox, I cannot type anymore.
I want to have a behavior where I can keep the Keyboard focus on textbox but should be able to control the buttons using TAB key as well. In a way, I need to have focus on textbox and the buttons at the same time. Is this possible?
Tried the FocusManager.IsFocusScope = "true", but this did not help.

Need to tap twice on touchscreen to click button in WPF

I have a WPF application that at one point brings up another window where the user can enter text in a field that is selected on open then click OK to save the text. This is working correctly on my desktop using a mouse, but when I run the application on a tablet (Surface Pro) the OK button needs to be tapped twice to save the text. The first tap highlights the button, then the second tap clicks it. Is there any way to allow the user to click the button with just one tap on the screen?
This only happens when the application switches to the new window. The main window only requires one tap to click buttons (Though I have noticed that they require two when switching back to the main window). It seems like this issue has to do with focus or something because if I tap somewhere on the new window before clicking OK, I can tap OK once and it will trigger the click event.
You probably need something like this in your code:
textBox1.Focus();
The other place to consider is the Tab order of the items on the form. Once the focus leaves the textbox, it moves to the next highest tab order object. It should be the OK button.
You can adjust the Tab order by looking at the properties of the objects on the form.
This is a bug in WPF combined with a touch display.
Because the textbox is focused, and you press the button, the textbox gets unfocused and the button gets focus. When the button has focus, you just have to press it in order to save your text.
There really isn't a thing you can do about it, since the touchscreen focuses first on the button before you can fire the event (I think it probaly is a kind of a safety feature).

WPF How To Tell If A Control Was Tabbed Into Focus?

I've got a ComboBox where I need to determine if it was tabbed into focus vs. clicked/touched into focus.
The ComboBox default behavior for being tabbed into focus does not open the drop-down part, which is different than if it is clicked/touched into focus...yet all three bring it into focus.

Buttons Are Automatically Selected (how to turn this off?)

I have winform buttons that when you load the form, a certain button is selected. What I mean by selected, is that if "enter" is pressed, the button is pressed.
How can I change my buttons so they don't do this anymore?
Your tab order is set in the order in which you add controls on the form. If your first control which can be pressed/selected/edited is that button which is getting pressed, the focus will automatically be on it when form is loaded.
You can cheat by setting the focus to some other control (maybe which is not visible? !hint * hint!) to avoid the button to be selected at first.
But also make sure tht button is not the AcceptButton of the form.
Two concepts have been touched on by Nayan and rerun:
1) AcceptButton
2) Tab order
There is one more I would add and then try to explain how the three things relate:
3) Focus
Focus means that a child control has the "keyboard focus". When a control has focus, it receives keyboard input and can respond to it. Focus is changed either by clicking a control with the mouse, or by using the Tab key.
Tab order is the order in which controls receive focus when the Tab key is pressed. It also determains which control initially gets focus (the first one in tab order).
The AcceptButton concept is a bit of a hybred. If a form's AcceptButton property is set to a button control, that button is pressed when the user presses the Enter key while focus is on any control that does not process the enter key itself. Typically the 'Ok' button on a form is set as the AcceptButton so that the user can enter data and press Enter as a shortcut to pressing the Ok button.
You need to set the acceptbutton on the form.
Element.Select() is what worked for me.

wpf textbox focus issue

I have a control with several textbox controls on it.
Now, when I press tab after I edit one of the textboxes, the focus is switched to the next textbox BUT I need to press an additional tab in order for it to enter the "editing" stage.
The first tab simply draws a dotted background on the textbox ... and the second one actually puts the cursor position inside the textbox. Is there a way when I press tab, to automatically set the cursor inside the textbox?
Thanks./
Are you sure you don't have any hidden controls or other controls that might be accepting focus before your textbox? Either way, you should be able to update the tabindex value of your controls so they follow a logical sequence when tab is pressed.

Categories