user1462922
user1462922

Reputation: 11

How to set focus on richeditbox in metro style app?

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.

Upvotes: 1

Views: 2168

Answers (1)

JP Alioto
JP Alioto

Reputation: 45127

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

SendBox.Focus(Windows.UI.Xaml.FocusState.Programmatic);

Upvotes: 2

Related Questions