/// <summary> /// This method is made Internal for testing purposes. /// </summary> internal void HighlightStartingMatch(TextBlock textBlock, string userInput, HighlightStyle styleInfo) { string text = textBlock.Text; if (!text.StartsWith(userInput, this.comparisonMode)) { return; } textBlock.Inlines.Clear(); Run firstRun = SuggestionItem.GetRunFromStyle(styleInfo); firstRun.Text = text.Substring(0, userInput.Length); textBlock.Inlines.Add(firstRun); this.highlightedRuns.Add(new KeyValuePair <Run, HighlightStyle>(firstRun, styleInfo)); int remainingLength = text.Length - userInput.Length; if (remainingLength != 0) { Run secondRun = new Run(); secondRun.Text = text.Substring(userInput.Length, remainingLength); textBlock.Inlines.Add(secondRun); } }
internal void PrepareContainerForSuggestionItem(DependencyObject element, object item) { SuggestionItem suggestionItem = element as SuggestionItem; suggestionItem.Attach(this, item); suggestionItem.HighlightInput(this.owner.suggestionsProvider.InputString); }
internal void OnItemTapped(SuggestionItem item) { if (this.ItemTapped != null) { this.ItemTapped(this, new SuggestionItemTappedEventArgs() { Item = item.DataItem }); } }
/// <summary> /// This method is made Internal for testing purposes. /// </summary> internal void HighlightAllMatches(TextBlock textBlock, string userInput, HighlightStyle styleInfo) { string text = textBlock.Text; int indexOfOccurance = text.IndexOf(userInput, this.comparisonMode); if (indexOfOccurance == -1) { return; } textBlock.Inlines.Clear(); int portionStart = 0; while (indexOfOccurance != -1) { string firstTextPortion = text.Substring(portionStart, indexOfOccurance - portionStart); if (!string.IsNullOrEmpty(firstTextPortion)) { Run firstRun = new Run(); firstRun.Text = firstTextPortion; textBlock.Inlines.Add(firstRun); } Run highLightedRun = SuggestionItem.GetRunFromStyle(styleInfo); highLightedRun.Text = text.Substring(indexOfOccurance, userInput.Length); textBlock.Inlines.Add(highLightedRun); this.highlightedRuns.Add(new KeyValuePair <Run, HighlightStyle>(highLightedRun, styleInfo)); int nextOccuranceIndex = text.IndexOf(userInput, indexOfOccurance + userInput.Length, this.comparisonMode); if (nextOccuranceIndex == -1) { int lastPortionStart = indexOfOccurance + userInput.Length; string lastPortion = text.Substring(lastPortionStart, text.Length - lastPortionStart); if (!string.IsNullOrEmpty(lastPortion)) { Run lastRun = new Run(); lastRun.Text = lastPortion; textBlock.Inlines.Add(lastRun); } } else { portionStart = indexOfOccurance + userInput.Length; } indexOfOccurance = nextOccuranceIndex; } }