/* * Retrieve the current predictions available for words/prefixed of 3 characters or more, * The predictions are set on a Databound variable to be pushed to the UI */ private void GetCurrentPredictions() { // Don't predict unless we have three letters minimum var tokens = GetInputTokens(_currentInput.ToString()); if (tokens.Length < 1 || tokens[tokens.Length - 1].Length < 3) { PredictiveWords.Clear(); SelectedPrediction = null; return; } PredictiveWords.Clear(); var predictedWords = _predictiveDictionary.GetWordPredictions(tokens[tokens.Length - 1]); if (predictedWords.Count > 0) { foreach (var word in predictedWords.Take(4)) { PredictiveWords.Add(word); } SelectedPrediction = PredictiveWords.First(); } else { SelectedPrediction = null; } _selectedPredictionIndex = 0; OnPropertyChanged("SelectedPrediction"); OnPropertyChanged("PredictiveWords"); }
/* * Confirm the currently selected prediction word and enter into the input text block */ private void SetSelectedWord() { var tokens = GetInputTokens(_currentInput.ToString()); var currentWord = tokens[tokens.Length - 1]; _currentInput.Remove(_currentInput.Length - currentWord.Length, currentWord.Length); _currentInput.Append(SelectedPrediction); PredictiveWords.Clear(); SelectedPrediction = null; _selectedPredictionIndex = 0; OnPropertyChanged("SelectedPrediction"); OnPropertyChanged("PredictiveWords"); }