本文整理汇总了C#中System.Windows.Documents.Paragraph.GetTextAfter方法的典型用法代码示例。如果您正苦于以下问题:C# Paragraph.GetTextAfter方法的具体用法?C# Paragraph.GetTextAfter怎么用?C# Paragraph.GetTextAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.Paragraph
的用法示例。
在下文中一共展示了Paragraph.GetTextAfter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractListOfWords
private List<string> ExtractListOfWords(Paragraph paragraph)
{
var caretIsWithin = (this.CaretPosition != null &&
this.CaretPosition.CompareTo(paragraph.ContentStart) >= 0 &&
this.CaretPosition.CompareTo(paragraph.ContentEnd) <= 0);
var list = new List<string>();
if (caretIsWithin)
{
var beforeText = paragraph.GetTextBefore(this.CaretPosition);
var afterText = paragraph.GetTextAfter(this.CaretPosition);
// enter key was pressed
if (beforeText == "" && afterText == "")
{
if (this.DisableAddingWhiteSpacesOnEnter)
{
return null;
}
// add white space to the new line - same as the previous line
var prev = paragraph.PreviousBlock as Paragraph;
if (prev != null)
{
var previousLine = prev.GetText();
var spaces = new StringBuilder();
foreach (var ch in previousLine)
{
if (ch == ' ' || ch == '\t')
{
spaces.Append(ch);
}
else
{
break;
}
}
if (spaces.Length > 0)
{
beforeText = spaces.ToString();
}
else
{
return null;
}
}
else
{
return null;
}
}
// else
if (beforeText != "") list.AddRange(this._paragraphProcessor.SplitWordsRegex.Split(beforeText));
list.Add(null);
if (afterText != "") list.AddRange(this._paragraphProcessor.SplitWordsRegex.Split(afterText));
}
else
{
var text = paragraph.GetText();
var array = this._paragraphProcessor.SplitWordsRegex.Split(text);
list.AddRange(array);
}
return list;
}
示例2: ExtractListOfWords
/// <summary>
///
/// </summary>
/// <param name="textBox"></param>
/// <param name="paragraph"></param>
/// <returns></returns>
private List<string> ExtractListOfWords(RichTextBox textBox, Paragraph paragraph)
{
// Check if caret position is within the word
var caretIsWithin = (textBox.CaretPosition != null &&
textBox.CaretPosition.CompareTo(paragraph.ContentStart) >= 0 &&
textBox.CaretPosition.CompareTo(paragraph.ContentEnd) <= 0);
var list = new List<string>();
// If caret is within the paragraph, we need to break it up into Inline objects and format the line
if (caretIsWithin) {
var beforeText = paragraph.GetTextBefore(textBox.CaretPosition);
var afterText = paragraph.GetTextAfter(textBox.CaretPosition);
// If there's no text on either side of the caret, we're on an empty line
if (beforeText == "" && afterText == "") {
if (this.DisableAddingWhiteSpacesOnEnter) {
return null;
}
// Add white space to the new line - same as the previous line
var prev = paragraph.PreviousBlock as Paragraph;
if (prev != null) {
var previousLine = prev.GetText();
var spaces = new StringBuilder();
foreach (var ch in previousLine) {
if (ch == ' ' || ch == '\t') {
spaces.Append(ch);
}
else {
break;
}
}
if (spaces.Length > 0) {
beforeText = spaces.ToString();
}
else {
return null;
}
}
else {
return null;
}
}
// If theres text before or after the caret, split the words and add them to the list
if (beforeText != "") {
list.AddRange(this.syntaxProcessor.SplitWordsRegex.Split(beforeText));
}
// Add null representing the caret
list.Add(null);
if (afterText != "") {
list.AddRange(this.syntaxProcessor.SplitWordsRegex.Split(afterText));
}
}
else {
// If caret is not in the paragraph, just add it as-is.
// It would already be formatted.
var text = paragraph.GetText();
var array = this.syntaxProcessor.SplitWordsRegex.Split(text);
list.AddRange(array);
}
return list;
}