Need to tap twice on touchscreen to click button in WPF - c#

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).

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.

Popup Control closes on fireing event

i have two controls. First is a comment control, which allow the user to create, update and delete comments. It got own MenĂ¼bar with add, safe, delete button.
If someone want to add this control in his form it could be to big. So i have a second control, which is just a PopupContainerEdit with PopupControl. In the popupcontrol i add the commentcontrol. So i have an popupcommentcontrol and if someone want to add it in his form he just need a place for a small button of the popupcontaineredit.
My problem is, if i change the list of commentars (save, delete) in the commentarcontrol i fire a event, so that the popup can check the change of the list. So the Popupcontrol know if there are comments or not and i can swap the icon of the button. The enduser directly see on the icon of the button if there are comments or not. But if i fire the event to tell my popup "hey the list changes" the popup window get closed.
Is there a possibility to stop this close if i fire the event?
regards

Silverlight combobox blocks interaction with other controls

I have a Silverlight view which has several layers of popups. It is a record search/edit page, which displays the results in a datagrid. There is a details view for each record that is then shown in a popup over the grid. Finally, the sections in the details view can be edited, and the edit form is displayed in a third popup. The search criteria is hidden when viewing data, but can be toggled into view.
The problem I am facing is that whenever the comboboxes on the edit popups are interacted with, it causes the layers below them to be un-clickable. In the screenshot I provided, if the user clicks on the Phone or Email comboboxes, even if they don't change the selections, and closes the topmost edit popup, then the delete, save, close, and view on map buttons no longer receive mouse interaction. They have mouseover styles that are not applied and they don't receive clicks. However, the New Group button does, but only below a certain point. It is behaving as if there is an invisible canvas/shape blocking mouse interaction.
Additionally, if the user slides out the Record Search panel (by clicking on the down arrow icon), the form somehow gets reset and those buttons are clickable again. Also, if the browser window gets resized the buttons are also clickable.
I've spent the better part of two days going through this, admittedly complicated, view and I'm positive there are no controls/canvases/shapes that I'm displaying that are being placed in the way, as I've added color/outlines to every canvas in the xaml.
At this point I am stumped and reconsidering redesigning the form to avoid this problem. Has anyone run into this and if so do you have a solution?

WinForms ComboBox - Event when Text Input is Clicked Into

I have a feature request that when a ComboBox is 'clicked into' that it clears the text so that the user can start entering in new data to search. Does anyone know of a way to hook into this? The 'click' event is raised on when the text is clicked as well as when the drop down arrow is also clicked (which opens up the drop down with items). I only want it to happen on the first, not the latter.
Right now I'm capturing the click event and filtering on the DroppedDown property like so:
if(!comboBox.DroppedDown)
{
// clear selection
}
This seems to work most of the time, but bugs out frequently as well... so its not 100%.
If anyone knows of a proper way to do this I would appreciate!
Don't handle the click event. For one thing, it won't fire if the user tabs the focus into the control. Use the Enter event which fires when the control receives focus. And rather than clearing text you should just select it all which will give the best of both worlds:
1) The user can start entering new text which will clear any old text or
2) tab past the control and leave the contained text as it was.
If you always remove the previous text you may anger users.
Try the "Enter" event. It happens when a control gains focus on the form.

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.

Categories