1

I have the following code:

 private async void SendMsg_Click(object sender, RoutedEventArgs e)
{
 RichEditBox.Document.SetText(TextSetOptions.None, "");
 await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
       if(RichEditBox!=null)
       SendBox.Focus(Windows.UI.Xaml.FocusState.Keyboard);
    });
 }

but when clicked,the RichEditBox didnot got focus.What's wrong with my code? thanks

Sorry,I forgot add this code:"MsgWebView.NavigateToString("Hello World!");".And I found the problem lies in here.So the whole code is like this:

private void SendMsg_Click(object sender, RoutedEventArgs e)
{
   MsgWebView.NavigateToString("Hello  World!");
   SendBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);

}

How to solve this problem? Best regards.

  • Are you trying to open the keyboard programmatically by setting the focus to the RTB? Also, is this in desktop or Metro? – N_A Jul 31 '12 at 16:46
  • possible duplicate of [how to hide on EditText soft keyboard windows 8 Metro Application?](http://stackoverflow.com/questions/10714431/how-to-hide-on-edittext-soft-keyboard-windows-8-metro-application) – N_A Jul 31 '12 at 16:56
  • This is in Metro.Thanks for your answer. – user1462922 Aug 01 '12 at 01:22

1 Answers1

2

You need to use the Programmatic option on FocusState (not Keyboard).

SendBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);
JP Alioto
  • 44,864
  • 6
  • 88
  • 112
  • Thanks for your answer.I found the problem is not the Keyboard,but the code :MsgWebView.NavigateToString("Hello World!");I added this code in the Click event,so the whole code is like this:Thanks for you answer.I found the problem is not the Keyboard,but the code :MsgWebView.NavigateToString("Hello World!");I added this code in the Click event,so the whole code is like this:'private void SendMsg_Click(object sender, RoutedEventArgs e) { MsgWebView.NavigateToString("Hello World!"); SendBox.Focus(Windows.UI.Xaml.FocusState.Keyboard); }); } – user1462922 Aug 01 '12 at 01:06