询问者
关于richeditbox,请问如何改变向追加内容的方向

问题
全部回复
-
RichTextBox里面的内容是FlowDocument形式,所以我们需要参照FlowDocument的节段形式找到你要插入的TextPointer 然后插入你的<Run/>过这段落
你参考下文档:https://msdn.microsoft.com/en-us/library/aa970909%28v=vs.100%29.aspx?f=255&MSPPError=-2147217396
How to: Insert an Element Into Text Programmatically https://msdn.microsoft.com/en-us/library/aa970562(v=vs.100).aspx
Bob Bao
Do you still use the same Windows 8 LockScreen always? Download Chameleon Win8 App quickly, that changes your LockScreen constantly.
你是否还在看着一成不变的Windows 8锁屏而烦恼,赶紧下载这个 百变锁屏 应用,让你的锁屏不断地变化起来。 -
这里是第二个链接中的代码:How to: Insert an Element Into Text Programmatically
using System; using System.Windows; using System.Windows.Media; using System.Windows.Controls; using System.Windows.Documents; namespace SDKSample { public partial class InsertInlineIntoTextExample : Page { public InsertInlineIntoTextExample() { // Create a paragraph with a short sentence Paragraph myParagraph = new Paragraph(new Run("Neptune has 72 times Earth's volume...")); // Create two TextPointers that will specify the text range the Span will cover TextPointer myTextPointer1 = myParagraph.ContentStart.GetPositionAtOffset(10); TextPointer myTextPointer2 = myParagraph.ContentEnd.GetPositionAtOffset(-5); // Create a Span that covers the range between the two TextPointers. Span mySpan = new Span(myTextPointer1, myTextPointer2); mySpan.Background = Brushes.Red; // Create a FlowDocument with the paragraph as its initial content. FlowDocument myFlowDocument = new FlowDocument(myParagraph); this.Content = myFlowDocument; } } }
上面的链接有很多代码和图,最好还是自己看一下。
-
Blocks类型是BlockCollection, 他有InsertBefore 和 InsertAfter两个方法,你可以获取第一个Paragraph然后往前插入一个new Parapragh
例子 https://msdn.microsoft.com/zh-cn/library/ms752359(v=vs.110).aspx
Paragraph p = new Paragraph(new Run("Text to insert...")); flowDoc.Blocks.InsertBefore(flowDoc.Blocks.FirstBlock, p);
Bob Bao
Do you still use the same Windows 8 LockScreen always? Download Chameleon Win8 App quickly, that changes your LockScreen constantly.
你是否还在看着一成不变的Windows 8锁屏而烦恼,赶紧下载这个 百变锁屏 应用,让你的锁屏不断地变化起来。
- 已编辑 Jie BaoModerator 2016年3月30日 5:37
-
非常感谢!
看到这里我对block的概念还是有点疑问,代码如下
<RichTextBox Name="myRichInput" Grid.ColumnSpan="3"> <FlowDocument Name="SendDocument"> <Paragraph Name="SendMessageParas"> <Run></Run> </Paragraph> </FlowDocument> </RichTextBox>
这是我定义的文本输入框 , 所有的输入都应该在run下面吧,我调试发现不管怎样输入,var blockCount = SendDocument.Blocks.Count;
取得得blockcount数都是1,请问flow doc是以什么方式来界定某个文本的block得呢