/// <summary> /// 显示自动提示 /// </summary> /// <param name="text"></param> public void ShowAutoComplete(string text) { var selectedText = text; ///分词 var selected = selectedText.Split(' '); selected = selected.Reverse().ToArray(); listbox.Items.Clear(); SourceText = /*GetRecentString(text);// */ selected.FirstOrDefault(); ///如果为空不提示 if (SourceText.All(c => c == ' ')) { return; } ///显示在智能提示框的内容 var showtext = keywords.Where(c => c.Contains(SourceText.ToUpper())).ToArray(); foreach (var ds in showtext) { var listItem = new ListBoxItem(); listItem.Content = ds; if (ds.All(x => x == ' ')) { continue; } ///减小提示框显示数量,避免卡顿 if (listbox.Items.Count > 10) { break; } listbox.Items.Add(listItem); } Rect rect = tb.GetRectFromCharacterIndex(tb.SelectionStart); Point point = rect.BottomLeft; pop.PlacementRectangle = rect; if (listbox.Items.Count == 0) { pop.IsOpen = false; return; } listbox.SelectedIndex = 0; pop.IsOpen = true; }