我想检查RichTextBox.CaretPosition是否在文档的末尾。
我有这段代码。
public void SetFormatInRichTextBox(RichTextBox rich,Color color,string property)
{
if (IsPositionContainedBetween(rich.CaretPosition, ((Paragraph)rich.Document.Blocks.LastBlock).Inlines.LastInline.ContentStart, ((Paragraph)rich.Document.Blocks.LastBlock).Inlines.LastInline.ContentEnd))
{
}
}
public bool IsPositionContainedBetween(TextPointer positionToTest, TextPointer start, TextPointer end)
{
if (!positionToTest.IsInSameDocument(start) || !positionToTest.IsInSameDocument(end))
return false;
return start.CompareTo(positionToTest) <= 0 && positionToTest.CompareTo(end) <= 0;
}
但是,方法IsPositionContainedBetween总是返回true。我使用WPF。
答案 0 :(得分:1)
我有解决方案
TextRange tr=new TextRange(rich.CaretPosition,rich.CaretPosition.Paragraph.ContentEnd);
if(tr.IsEmpty)
{
//caret is at the end of paragraph
}