I have a WinForms application. The problem is that a virtual keyboard doesn't appear when I enter the TextBox on my tablet with Windows 10. I also have some TextBox to enter password (with PasswordChar property set). In that TextBox virtual keyboard appears correctly.
So, to make the experiment clear I made a sample WinForms application and added a few TextBox on the Form, one of them for entering password (with PassowordChar property set). And it appears that even in a clear sample application virtual keyboard didn't appear for usual TextBox and appeared for PasswordChar TextBox.
So, can I fix the problem in any way?
Or should I just wait for some updates?
Related
This has me baffled.
I've written a popup box which consists of a WinForms UserControl hosted inside a WindowsFormsHost, which, in turn, is hosted in a Primitives.Popup which is displayed on the screen. The whole application is WPF, but this control was lifted from an earlier application written in WinForms.
The popup is activated by an external event (an incoming phone call from a CTI Server).
Inside the UserControl is a textbox control. When the user clicks in the text box, I call the Focus method on the Popup, then call the Focus method on the textbox. The textbox gets the focus. I can be fairly sure of that because the box shows a cursor after clicking in it, and also I have a "GotFocus" event handler that prints a debugging message.
However, if there was another program active at the time the incoming event occurs, any keys that are pressed on the keyboard continue to go to that program, not to the text box. Only if the user clicks in another part of my application (i.e., part of the screen outside the popup) to make it the active program, and then clicks in the text box is the text box able to receive keyboard input.
I hope I've given enough information without overwhelming you with the myriad of details. If there's something else anyone needs to point me in the right direction, I'll be happy to provide it.
Because the WinForm TextBox is hosted, setting focus on it does not activate the hosting WPF Window. Add a line to activate the Window.
private void TextBox_Click(object sender, EventArgs e)
{
this.Activate(); //activate the Window
(sender as System.Windows.Forms.TextBox).Focus();
}
I'm trying to integrate XNA into a WPF window, using the WindowsFormsHost control in the WPF window. I've got a very strange problem that whenever XNA is running, my keyboard input into my WPF window controls don't work. More weirdly, this is happening not for all keys. It happens for all the letters and numbers, but, for example, backspace or delete key work. I first thought this was due to XNA hooking up to the keyboard input and handling all the key presses, and the events weren't being routed to my WPF window. But weirdly, they DO get handled by the OnKeyDown. I've created a custom TextBox class that derives from normal TextBox, overrided the OnKeyDown, put a breakpoint in, and it worked. The debugger stepped on the breakpoint. So I was wrong: XNA wasn't blocking the key events from reaching the WPF window (or its controls), my TextBox IS getting the correct keyboard event, but it just doesn't work. I press 'A' on my keyboard, OnKeyDown gets called, but it doesn't append 'A' into the textbox. The backspace key, on the other hand, works normally. I copy paste some text into the field using mouse right click, and I click on the middle of the text (arrows don't work too), I can delete the text by pressing backspace, but I can't type anything.
What can be the reason? I am not really good with WPF's input handling, but normally, if my TextBox DOES get the OnKeyDown event (with the right argument), it should append the letter that I've pressed. As soon as I end the XNA game, things start behaving correctly. What can be the reason for the controls behaving abnormally?
Someone else has ran into the same problem here: http://forums.create.msdn.com/forums/p/98145/584961.aspx and they've found the solution to the problem (they've also linked to this question, too)
The interoperability of XNA and WPF needs a little tweak:
System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(this);
This code should be pasted to the constructor of the WPF window that will be hosting the XNA content. I've pasted it to the constructr after InitializeComponent() and it worked.
Literally, I want to know that.
In some case, .Focus() appear better than SetFocusedElement(). But another case, it's reversal. So I must know what's different things are there.
Additionally, by MSDN, .Focus() is for keyboard focus, and SetFocusedElement is for logical focus. But I can't feel different thing between logical focus and keyboard focus.
The keyboard focus is generally easier to understand, as that is effectively the control that would receive keyboard input if the user typed. So if you click in a TextBox it will receive keyboard focus and you can start typing. Other controls have other behaviors and may not really support the keyboard, but they can still get the keyboard focus.
For logical focus, your application can be made up of several parts. For example, most applications would have a ToolBar/Ribbon at the top and then their main content below. Now, imagine that your content is a TextBox that currently has the keyboard focus. When you click in a ToolBar/Ribbon control, the keyboard focus is moved to that control. But you really want to "remember" that the TextBox in your content had the keyboard focus before.
To achieve this the ToolBar/Ribbon will create new "focus scope". So when you click in the ToolBar/Ribbon control, you move the keyboard focus but the TextBox still has the logical focus for the window. That allows the TextBox to be given the keyboard focus back when the user is done working with the ToolBar/Ribbon.
The same holds true if you interact with another application, as your application doesn't have the keyboard focus. When you go back to working in your application, it uses the logical focus to know who had keyboard focus last (and should have it restored).
Using FocusManager.SetFocusedElement(), you can specify a UserControl of which you want to set focus on an element. So you can set focus on a control that is in a different part of your program.
Control.Focus() is just straightforward, you set focus on the said control (which is more intuitive).
Wild guess: you use FocusManager.SetFocusedElement() improperly, resulting in unwanted behaviors but bottom line, it's the same thing really.
Sidenote: "logical" focus and "keyboard" focus are 2 different things in WPF.
I'd like the default windows system sound to play when a user attempts to enter text into a WPF TextBox which has already reached it's MaxLength value. How is this possible?
I'm not used to sound playing in WPF, but I suggest you to suscribe to the KeyDown event of your textbox, and test the number of characters in the textbox against its maximal capacity.
I have an MVVM application with various TextBox controls and a virtual keypad. (This application is to run on a touch screen system, with no keyboard). To change the value of a TextBox, the user has to touch the TextBox and then use the virtual keypad to enter a number. How can my VM know which TextBox to change when it gets the command from the keypad?
if you mean WPF use FocusManager.GetFocusedElement also look here
The ViewMoel is unconcerned with the View, and as such this should not be passed to the ViewMdel.
If I needed to track this, I would use the View's codebehind (I know, I know) or create a WPF behavior* that does this for me.
*using Attached DependencyProperties, is normally how I do this.