1

I have a RichEditBox for which I want to turn the TextPrediction on and off while the user is typing. This is the code I am trying but its just not working. It requires the keyboard to be relaunched/reopened to show the changes.

private void PostRichEditBox_SelectionChanged(object sender, RoutedEventArgs e)
{
     if(somecondition)
     {
           Searchterm.Text = mentionText;
           var scope = new InputScope();
           var inputScopeName = new InputScopeName { NameValue = InputScopeNameValue.NameOrPhoneNumber };

           scope.Names.Add(inputScopeName);

           PostRichEditBox.InputScope = scope;
           PostRichEditBox.IsTextPredictionEnabled = true;
      }
      else
      {
           var scope = new InputScope();
           var inputScopeName = new InputScopeName { NameValue = InputScopeNameValue.Chat };

           scope.Names.Add(inputScopeName);

           PostRichEditBox.InputScope = scope;

           PostRichEditBox.IsTextPredictionEnabled = false;
       }
}

I know this can be done because Rudy Huyn's 6tag does this when '@' is typed and then it shows a list of friends suggestions in place of text predictions over the keyboard. I asked him on twitter about how he does this. He just replied by changing inputmode(I think he meant inputscope). How do I do this?

Rishabh876
  • 3,010
  • 2
  • 20
  • 37
  • My guess is it would not be possible, because you are changing a keyboard this way. You can try to unfocus, change scope, and focus again, but it would lead to bad UX, as you are unlikely to do it fast enough for user not to notice. – Paweł Mach Jul 27 '15 at 06:27
  • @PawełMach But Rudy is doing it in his app. Which is working just fine. – Rishabh876 Jul 27 '15 at 06:33
  • You have `PostRichEditBox.IsTextPredictionEnabled = true` on both your code paths, is that on purpose? Tried setting it to false and it seems to work, with a one letter delay which seems consistent with the 6tag experience (when you type '@', the autosuggestion bar is still visible, though empty, and vanishes when you start typing the name) – Kevin Gosse Jul 27 '15 at 08:06
  • @KooKiz Sorry it was false only in my code. I copy pasted the same code and forgot to change that. Let me check again if that delay thing actually is working. – Rishabh876 Jul 27 '15 at 08:48
  • @KooKiz Yup its actually working. I forgot to change IsTextPredictionEnable = true to false. Thanks – Rishabh876 Jul 27 '15 at 09:26
  • @KooKiz But even if the predictions are off. Its still taking that space. – Rishabh876 Jul 27 '15 at 09:36

1 Answers1

0

Because the prediction bar was not going away even if the predictions are turned off. It requires the keyboard to close and reopen to update the predictionBar so I have made some changes. I am now focusing on the UserControl then back to RichEditBox. And UX wise its not really noticeable as the keyboard never collapses.

if (PostRichEditBox.IsTextPredictionEnabled)
                {
                   this.Focus(Windows.UI.Xaml.FocusState.Keyboard);
                    var scope = new InputScope();
                    var inputScopeName = new InputScopeName { NameValue = InputScopeNameValue.NameOrPhoneNumber };

                    scope.Names.Add(inputScopeName);

                    PostRichEditBox.InputScope = scope;
                    PostRichEditBox.IsTextPredictionEnabled = false;
                    PostRichEditBox.Focus(Windows.UI.Xaml.FocusState.Keyboard);
                 }
Rishabh876
  • 3,010
  • 2
  • 20
  • 37