本文整理汇总了C#中System.Windows.Documents.TextPointer.GetListAncestor方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetListAncestor方法的具体用法?C# TextPointer.GetListAncestor怎么用?C# TextPointer.GetListAncestor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.GetListAncestor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SplitListsForFlowDirectionChange
// Checks if start and end positions are parented by a List.
// If so, unindents list items between (start - start's list end) or (end's list start - end)
// until they are parented by a top level list.
// Then, if needed, splits the list(s) at start and/or end positions.
// Returns false if splitting is not successful due to a failing unindent operation on any nested lists.
internal static bool SplitListsForFlowDirectionChange(TextPointer start, TextPointer end, object newFlowDirectionValue)
{
ListItem startListItem = start.GetListAncestor();
// Unindent startListItem's list to prepare for a split, if the List's FlowDirection value is different.
if (startListItem != null &&
startListItem.List != null && // Check for unparented list items
!TextSchema.ValuesAreEqual(/*newValue*/newFlowDirectionValue, /*currentValue*/startListItem.List.GetValue(Paragraph.FlowDirectionProperty)))
{
while (startListItem != null &&
startListItem.List != null &&
startListItem.List.Parent is ListItem)
{
// startListItem is within a nested List.
if (!UnindentListItems(new TextRange(start, GetPositionAfterList(startListItem.List))))
{
return false;
}
startListItem = start.GetListAncestor();
}
}
ListItem endListItem = end.GetListAncestor();
// Unindent endListItem's list to prepare for a split, if the List's FlowDirection value is different.
if (endListItem != null &&
endListItem.List != null &&
!TextSchema.ValuesAreEqual(/*newValue*/newFlowDirectionValue, /*currentValue*/endListItem.List.GetValue(Paragraph.FlowDirectionProperty)))
{
if (startListItem != null && startListItem.List != null &&
endListItem.List.ElementEnd.CompareTo(startListItem.List.ElementEnd) < 0)
{
// endListItem's List is contained within startListItem's List.
// No need to unindent endListItem.
}
else
{
while (endListItem != null &&
endListItem.List != null &&
endListItem.List.Parent is ListItem)
{
// endListItem is within a nested List.
if (!UnindentListItems(new TextRange(endListItem.List.ContentStart, GetPositionAfterList(endListItem.List))))
{
return false;
}
endListItem = end.GetListAncestor();
}
}
}
// Split list(s) at boundary position(s) if
// 1. startListItem is not the first list item within its list (or endListItem is not the last one)
// and
// 2. start/end's parent List's flow direction value is different than the new value being set
if ((startListItem = start.GetListAncestor()) != null && startListItem.PreviousListItem != null &&
startListItem.List != null && // Check for unparented list items
(!TextSchema.ValuesAreEqual(/*newValue*/newFlowDirectionValue, /*currentValue*/startListItem.List.GetValue(Paragraph.FlowDirectionProperty))))
{
Invariant.Assert(!(startListItem.List.Parent is ListItem), "startListItem's list must not be nested!");
TextRangeEdit.SplitElement(startListItem.ElementStart);
}
if ((endListItem = end.GetListAncestor()) != null &&
endListItem.List != null && // Check for unparented list items
(!TextSchema.ValuesAreEqual(/*newValue*/newFlowDirectionValue, /*currentValue*/endListItem.List.GetValue(Paragraph.FlowDirectionProperty))))
{
// Walk up from endListItem to find the topmost listitem that contains it.
if (endListItem.List.Parent is ListItem)
{
while (endListItem.List != null && endListItem.List.Parent is ListItem)
{
endListItem = (ListItem)endListItem.List.Parent;
}
}
if (endListItem.List != null && endListItem.NextListItem != null)
{
Invariant.Assert(!(endListItem.List.Parent is ListItem), "endListItem's list must not be nested!");
TextRangeEdit.SplitElement(endListItem.ElementEnd);
}
}
return true;
}
示例2: SetParagraphProperty
/// <summary>
/// Applies formatting properties for whole block elements.
/// </summary>
/// <param name="start">
/// a position within first block in sequence
/// </param>
/// <param name="end">
/// a positionn within last block in sequence
/// </param>
/// <param name="property">
/// property changed on blocks
/// </param>
/// <param name="value">
/// value for the property
/// </param>
/// <param name="propertyValueAction">
/// Specifies how to use the value - as absolute, as increment or a decrement.
/// </param>
internal static void SetParagraphProperty(TextPointer start, TextPointer end, DependencyProperty property, object value, PropertyValueAction propertyValueAction)
{
Invariant.Assert(start != null, "null check: start");
Invariant.Assert(end != null, "null check: end");
Invariant.Assert(start.CompareTo(end) <= 0, "expecting: start <= end");
Invariant.Assert(property != null, "null check: property");
// Exclude last opening tag to avoid affecting a paragraph following the selection
end = (TextPointer)TextRangeEdit.GetAdjustedRangeEnd(start, end);
// Expand start pointer to the beginning of the first paragraph/blockuicontainer
Block startParagraphOrBlockUIContainer = start.ParagraphOrBlockUIContainer;
if (startParagraphOrBlockUIContainer != null)
{
start = startParagraphOrBlockUIContainer.ContentStart;
}
// Applying FlowDirection requires splitting all containing lists on the range boundaries
// because the property is applied to whole List element (to affect bullet appearence)
if (property == Block.FlowDirectionProperty)
{
// Split any boundary lists if needed.
// We want to maintain the invariant that all lists and paragraphs within a list, have the same FlowDirection value.
// If paragraph FlowDirection command requests a different value of FlowDirection on parts of a list,
// we split the list to maintain this invariant.
if (!TextRangeEditLists.SplitListsForFlowDirectionChange(start, end, value))
{
// If lists at start and end cannot be split successfully, we cannot apply FlowDirection property to the paragraph content.
return;
}
// And expand range start to the beginning of the containing list
ListItem listItem = start.GetListAncestor();
if (listItem != null && listItem.List != null)
{
start = listItem.List.ElementStart;
}
}
// Walk all paragraphs in the affected segment. For FlowDirection property, also walk lists.
SetParagraphPropertyWorker(start, end, property, value, propertyValueAction);
}