When I try to add a text in the TextBox from a canvas using handwriting, the cursor go to the TextBox and the keyboard shows, and I try to add some code like make the TextBox isReadonly or trying to hide the keyboard and doesn't work.
I want every time select an item from the ListBox the item add to the TextBox without showing the keyboard. the action on RecognizedListBox_SelectionChanged a ListBox
private void RecognizedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (RecognizedListBox.SelectedItem == null)
return;
//gte the selected item from listbox
string inputTextWritePad = RecognizedListBox.SelectedItem.ToString();
//add the item to RichEditBox
MyTextNote.Text += inputTextWritePad + " ";
//clear the canvas return the listbox to vide
ClearAllClick(sender, e);
}
If I add isReadonly for TextBox, it will permanent disable to edit it, and I can't add any text using keyboard. I don't know where I will put my code, or verify when I need the keyboard to use it.
I see if I need to hide the keyboard, I must have an event for the keyboard button or something like this
private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e)
{
if(e.Key==Windows.System.VirtualKey.Enter)
{
Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();
}
}
but nothing to figure out!!
update 1:
I add this code
private void MyTextNote_GotFocus(object sender, RoutedEventArgs e)
{
InputPane.GetForCurrentView().TryHide();
}
and help me to not show the keyboard, but I need to show it when I clicked the textbox, I try whit tapped but nothing help.
Here's a property to avoid displaying Keyboard if your TextBox receives focus programmatically :
<TextBox PreventKeyboardDisplayOnProgrammaticFocus="true"/>
Set this property to true to prevent the onscreen touch keyboard from
showing when focus is programmatically set on a text box. By default,
the onscreen touch keyboard is displayed whenever focus moves to an
editable text box and the most recent input was generated by touch.
Official Doc
Related
i am building a virtual keyboard to suit the needs of the touch screen machine i'm going to be deploying on. i am using a popup window for the keyboard and have been able to wire all number buttons as follow, here's my virtual keyboard class
public partial class NumKeypad : Window
{
withoutB withoutbvn;
enterBvn ebvnn;
public NumKeypad()
{
InitializeComponent();
}
public NumKeypad(withoutB wobvn)
{
InitializeComponent();
withoutbvn = wobvn;
}
private void one_Click(object sender, RoutedEventArgs e)
{
var focusedElt = FocusManager.GetFocusedElement(withoutbvn);
var tbox = focusedElt as TextBox;
try
{
withoutbvn.ph.Text += (((sender as Button).Content as Border).Child as TextBlock).Text;//this works, but this is assigning directly to only one control. i want to assign to whatever control that has focus
}
catch (Exception ex)
{
}
}
}
on the first line of the one_click function(which handles all input button click) i'm trying to get a reference to the element currently focused in the page whose instance is "withoutbvn".
on the second line, i am tryin to convert the element to a text box so i can write to its text property. but that keeps returning null. meaning when this pop up windows come up(the keyboard pop up window comes up when a textbox or any other input element receives focus), i cannot get a reference to the focused textbox so i cannot write to it. Please how do i ensure a focused textbox remains focused so that i can assign its text property from a pop up window? Or if there's a better way to do this, pls point me in the right direction. Thanks
I've used this keyboard for WPF :
keyboard control wpf
It is a popup control which can be customized as you wish. You have the entire code and it's free. In my case I had to adjust the popup (layout and to add the German letters) and was pretty straightforward.
I also had to show a numeric keyboard, and I've used the same keyboard but with a simpler layout. Behind the scenes, all it is very simple: you have to define a key in a grid, place it where you want and make sure you generate on click the corresponding virtual key code.
i used the popup control to create the keyboard, used buttons to create all keys and wired a single event handler to all input buttons, then different event handlers for the backspace and enter buttons. once any letter, number or symbol button is clicked, the following function gets called.
try
{
IInputElement focusedControl = Keyboard.FocusedElement;
var foc = focusedControl as TextBox;
foc.Text += (((sender as Button).Content as Border).Child as TextBlock).Text;
}
catch (Exception)
{
}
that inserts the button's text to the control in focus. This is pretty basic. i'll appreciate more suggestion on how i can expand on this. Thanks
WPF's TextBox has a property named IsInactiveSelectionHighlightEnabled. I set this property to true in order to make a TextBox always show selection. However, it doesn't work in this case:
private void button_Click(object sender, RoutedEventArgs e) {
textBox.Select(0, 10);
}
I just want to see the selection after clicking the button. But selection will not appear until I right click the TextBox. Why? Am I miss something?
You should have the Keyboard focus on your textbox to select the text in it.
Add this code to your button click event before the selection.
Keyboard.Focus(textBox);
Hope it helps.
I use a textbox as an address bar for a WP browser application. I want to select all text when a user selects the textbox and also to modify the opacity.
I tried using GotFocus method to do that. I see that the whole text is selected for 1 second or so and then it is deselected. I also need to modify the opacity once the focus is on textbox and when the textbox loses focus. Using GotFocus method I can modify the opacity but when the focus is lost, when I set again the opacity percent nothing happens.
Can you give me a hint regarding the events that determine the text to be selected for a short period of time and for the opacity problem?
private void URLTextBox_GotFocus(object sender, RoutedEventArgs e)
{
URLTextBox.Opacity = 50;
URLTextbOX.SelectAll();
}
private void URLTextBox_LostFocus(object sender, RoutedEventArgs e)
{
URLTextBox.Opacity = 10;
}
You can try subscribing to one of the tunnelling events (PreviewGotKeyboardFocus and PreviewLostKeyboardFocus) instead of the GotFocus event.
I have a small window with 2 textboxes in a grid databinded to some properties, it is called from context menu of another window. I made one of textboxes focused after appearing by
<Grid FocusManager.FocusedElement="{Binding ElementName=priceBox}">
I would like to have behavior that Text in TextBox would be selected (dark blue background) so if I start type new symbols old ones being immediately deleted. I don't want to delete old symbols first. Same behavior I would like to have after I press Tab to switch to next textbox.
Is there any textbox settings to achieve this?
I have very old winforms applications and It looks like it was behaving this way by default.
You will have to set Keyboard focus on the TextBox before selecting the text
e.g:
private void SelectAllText(object sender, RoutedEventArgs e)
{
var textBox = e.OriginalSource as TextBox;
if (textBox != null)
{
Keyboard.Focus(textBox);
textBox.SelectAll();
}
}
In my app,I just have a page with four text boxes, so when i click a text box soft keyboard appears, now when i want to move to next textbox then i have to tap outside the textbox to make the keyboard disappear and then click on another text box. I don't think it is user friendly, so i have two options,
1)To change the functionality of return button(to make it work as tab).
2)To reduce the frame size and so scrolling will be enabled.
How can I do the foretold two options in windows phone 7??
for the first option
Make return key of the input panel work like tab key.
make key down event of 1st textbox like this
private void txt1_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Enter)
{
txt2.Focus();
}
}
similarly make this event for txt2 and txt3 and give focus accordingly and on on txt4 keydown event focus the main grid.
and about the 2nd way. Its a big problem in wp according to my knowledge.
For moving to next textbox #Amu 's answer will work perfect, and to dismiss the keyboard,
if (e.Key == System.Windows.Input.Key.Enter)
{
this.Focus();
}
That will take the focus away from your text box and will bring it to your screen.
And So keyboard will disappear!