public void InsertText(string text, int offset) { Focus(); CaretPosition.DeleteTextInRun(-offset); //remove the first part of the word we are replacing CaretPosition.InsertTextInRun(text); TextPointer pointer = CaretPosition.GetPositionAtOffset(text.Length); if (pointer != null) { CaretPosition = pointer; } }
private void InsertText(string text) { if (isBurnMode) { return; } Focus(); //删除输入 包括@ TextPointer p = CaretPosition.GetPositionAtOffset(-sbLastWords.Length - 1); if (p != null) { CaretPosition = p; } var getGroupMembersUser = RichTextSource.FirstOrDefault(c => c.userNum + c.userName == text); text = "@" + text; CaretPosition.DeleteTextInRun(sbLastWords.Length + 1); //pTalk = p.Paragraph; //插入选中项 todo TextBlock tbLeft = new TextBlock() { Text = text, FontSize = 12, Foreground = new SolidColorBrush(talkColor) }; if (getGroupMembersUser != null) { tbLeft.Tag = getGroupMembersUser.userId; } else if (text.Contains("全体")) { tbLeft.Tag = groupId; } TextPointer point = this.Selection.Start; InlineUIContainer uiContainer = new InlineUIContainer(tbLeft, point); TextPointer nextPoint = uiContainer.ContentEnd; this.CaretPosition = nextPoint; this.CaretPosition.InsertTextInRun(" ");//加入空格 //pTalk.Inlines.Add(tbLeft); //this.Document.Blocks.Add(pTalk); //TextPointer pointer = this.Document.ContentEnd; //if (pointer != null) //{ // CaretPosition = pointer; //} //CaretPosition.InsertTextInRun(" ");//加入空格 //TextPointer pp = CaretPosition.GetPositionAtOffset(1); //if (pp != null) //{ // CaretPosition = pp; //} }
private void AppendContainer(Inline container) { _suppressRecognition = true; CaretPosition = CaretPosition.DocumentEnd; var length = CaretPosition.GetTextRunLength(LogicalDirection.Backward); CaretPosition = CaretPosition.GetPositionAtOffset(-length); if (CaretPosition != null) { CaretPosition.DeleteTextInRun(length); var paragraph = CaretPosition.Paragraph; if (paragraph != null) { paragraph.Inlines.Add(container); } CaretPosition = CaretPosition.DocumentEnd; } _suppressRecognition = false; }