/// <summary> /// 处理补全提示的打开、更新、关闭 /// </summary> /// <remarks> /// 不能在 PreviewTextInput 中处理,因为中英文输入行为不一致。 /// </remarks> private void TagSearchBox_TextChanged(object sender, TextChangedEventArgs e) { //需判断标志位,以免删除时触发 if (!previewTextInputHappend) { return; } if (IntelliUtils.IsQuoteOdd(tagSearchBox.Text) && tagSearchBox.CaretIndex == tagSearchBox.Text.Length) { string prefix = IntelliUtils.ExtractPrefix(tagSearchBox.Text); winVM.RefreshIntelliItems(prefix); if (winVM.IntelliItems.Count > 0) { intelliPopup.IsOpen = true; intelliLst.SelectedIndex = 0; if (prefix.Length == 0) { intelliPopup.PlacementRectangle = tagSearchBox.GetRectFromCharacterIndex( tagSearchBox.Text.Length); } } else { intelliPopup.IsOpen = false; } } else { intelliPopup.IsOpen = false; } previewTextInputHappend = false; }
/// <summary> /// 把选中的提示放到输入框中,并关闭提示 /// </summary> private void UseIntelliThenClose() { if (intelliLst.SelectedItem != null) { string tagName = IntelliUtils.EscapeTagName( (intelliLst.SelectedItem as IntelliItem).Name); int prefixLen = IntelliUtils.ExtractPrefix(tagSearchBox.Text).Length; string textWithoutPrefix = tagSearchBox.Text.Substring( 0, tagSearchBox.Text.Length - prefixLen); tagSearchBox.Text = textWithoutPrefix + tagName + "\" "; tagSearchBox.CaretIndex = tagSearchBox.Text.Length; } intelliPopup.IsOpen = false; }