本文整理汇总了C#中Run.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# Run.Descendants方法的具体用法?C# Run.Descendants怎么用?C# Run.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Run
的用法示例。
在下文中一共展示了Run.Descendants方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveRunTextBeforeIndex
private static void RemoveRunTextBeforeIndex(Run run, int index)
{
int cursor = 0;
var texts = run.Descendants<Text>().ToList();
Debug.Assert(texts.Count > 0, "Run contains no Text elements.");
for (int textIndex = 0; textIndex < texts.Count; textIndex++)
{
var t = texts[textIndex];
cursor += t.Text.Length;
if (cursor <= index)
{
t.Remove();
}
else
{
int startIndex = index - cursor + t.Text.Length;
t.Text = t.Text.Substring(startIndex);
if (t.Text.Length > 0)
{
if (Char.IsWhiteSpace(t.Text[0]))
{
t.Space = SpaceProcessingModeValues.Preserve;
}
}
break;
}
}
}
示例2: FindByInnerText
protected static Text FindByInnerText(Run run, string innerText)
{
return run.Descendants<Text>().FirstOrDefault(x => x.Text.Contains(innerText));
}
示例3: RemoveRunTextAfterIndex
private static void RemoveRunTextAfterIndex(Run run, int index)
{
int cursor = run.InnerText.Length;
var texts = run.Descendants<Text>().ToList();
Debug.Assert(texts.Count > 0, "Run contains no Text elements.");
for (int textIndex = texts.Count - 1; textIndex >= 0; textIndex--)
{
var t = texts[textIndex];
cursor -= t.Text.Length;
if (cursor >= index)
{
t.Remove();
}
else
{
int startIndex = 0;
int length = index - cursor;
t.Text = t.Text.Substring(startIndex, length);
if (t.Text.Length > 0)
{
if (Char.IsWhiteSpace(t.Text.Last<Char>()))
{
t.Space = SpaceProcessingModeValues.Preserve;
}
}
break;
}
}
}