Reputation: 540
I have this piece of code for button in my Windows Phone 8.1 Store App project (not the Silverlight):
private void CursorRightButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(QueryTextBox.Text)) return;
QueryTextBox.Focus(FocusState.Keyboard); //also i tried FocusState.Pointer
QueryTextBox.Select((TextBox.SelectionStart + 1) % (TextBox.Text.Length + 1), 0);
}
As you can see, I am tring to move cursor to right in text programmatically and the problem is that it hides soft keyboard and then shows it again after tapping button. I need to have keyboard on while tapping this button.
I tried to tinker with Focus() methods for sender and TextBox objects but I couldn't find any possible solution.
So the question is, how do you force keyboard not to loose focus/not to hide while tapping on controls?
Upvotes: 2
Views: 673
Reputation: 540
I found out with Sajeetharans help that I need to set IsTabStop value on controls to false. Then keyboard will stay there. I did it in constructor of my page like this
public MainPage()
{
InitializeComponent();
CursorLeftButton.IsTabStop = false;
CursorRightButton.IsTabStop = false;
}
and my button method
private void CursorRightButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(TextBox.Text)) return;
TextBox.Select((TextBox.SelectionStart + 1) % (TextBox.Text.Length + 1), 0);
}
Upvotes: 5
Reputation: 222582
Add a loaded event to your container say grid,
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
this.IsTabStop = true;
set focus on the control , say a textblock
Txtblock1.Focus();
}
How To Programmatically Dismiss the SIP (keyboard)
Upvotes: 1