本文整理汇总了C#中System.Windows.Documents.TextPointer.GetLogicalTreeNode方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetLogicalTreeNode方法的具体用法?C# TextPointer.GetLogicalTreeNode怎么用?C# TextPointer.GetLogicalTreeNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.GetLogicalTreeNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertElementInternal
// InsertElement worker. Adds a TextElement to the tree.
// If element is already in a tree, we remove it, do a deep copy of its content,
// and insert that too.
internal void InsertElementInternal(TextPointer startPosition, TextPointer endPosition, TextElement element)
{
TextTreeTextElementNode elementNode;
int symbolOffset;
int childSymbolCount;
TextPointer startEdgePosition;
TextPointer endEdgePosition;
char[] elementText;
ExtractChangeEventArgs extractChangeEventArgs;
DependencyObject parentLogicalNode;
bool newElementNode;
int deltaCharCount;
Invariant.Assert(!this.PlainTextOnly);
Invariant.Assert(startPosition.TextContainer == this);
Invariant.Assert(endPosition.TextContainer == this);
DemandCreateText();
startPosition.SyncToTreeGeneration();
endPosition.SyncToTreeGeneration();
bool scopesExistingContent = startPosition.CompareTo(endPosition) != 0;
BeforeAddChange();
// Remove element from any previous tree.
// When called from a public method we already checked all the
// illegal cases in CanInsertElementInternal.
if (element.TextElementNode != null)
{
// This element is already in a tree. Remove it!
bool sameTextContainer = (this == element.TextContainer);
if (!sameTextContainer)
{
// This is a cross-tree extract.
// We need to start a change block now, so that we can
// raise a Changing event inside ExtractElementInternal
// before raising the LogicalTree events below.
// We'll make an EndChange call to wrap up below.
element.TextContainer.BeginChange();
}
bool exceptionThrown = true;
try
{
// ExtractElementInternal will raise LogicalTree events which
// could raise exceptions from external code.
elementText = element.TextContainer.ExtractElementInternal(element, true /* deep */, out extractChangeEventArgs);
exceptionThrown = false;
}
finally
{
if (exceptionThrown && !sameTextContainer)
{
// If an exception is thrown, make sure we close the
// change block we opened above before unwinding.
element.TextContainer.EndChange();
}
}
elementNode = element.TextElementNode;
deltaCharCount = extractChangeEventArgs.ChildIMECharCount;
if (sameTextContainer)
{
// Re-[....] the TextPointers in case we just extracted from this tree.
startPosition.SyncToTreeGeneration();
endPosition.SyncToTreeGeneration();
// We must add the extract change now, before we move on to the insert.
// (When !sameTextContainer we want to delay the notification in the extract
// tree until the insert tree is in an accessible state, ie at the end of this method.)
extractChangeEventArgs.AddChange();
// Don't re-raise the change below.
extractChangeEventArgs = null;
}
newElementNode = false;
}
else
{
// Allocate a node in the tree to hold the element.
elementText = null;
elementNode = new TextTreeTextElementNode();
deltaCharCount = 0;
newElementNode = true;
extractChangeEventArgs = null;
}
parentLogicalNode = startPosition.GetLogicalTreeNode();
// Invalidate any TextElementCollection that depends on the parent.
// Make sure we do that before raising any public events.
//.........这里部分代码省略.........
示例2: InsertEmbeddedObjectInternal
// InsertEmbeddedObject worker. Adds a UIElement to the tree.
internal void InsertEmbeddedObjectInternal(TextPointer position, DependencyObject embeddedObject)
{
TextTreeNode objectNode;
int symbolOffset;
DependencyObject parentLogicalNode;
TextPointer insertPosition;
Invariant.Assert(!this.PlainTextOnly);
DemandCreateText();
position.SyncToTreeGeneration();
BeforeAddChange();
parentLogicalNode = position.GetLogicalTreeNode();
// Insert a node.
objectNode = new TextTreeObjectNode(embeddedObject);
objectNode.InsertAtPosition(position);
// Update the symbol count.
UpdateContainerSymbolCount(objectNode.GetContainingNode(), objectNode.SymbolCount, objectNode.IMECharCount);
// Insert the corresponding text.
symbolOffset = objectNode.GetSymbolOffset(this.Generation);
TextTreeText.InsertObject(_rootNode.RootTextBlock, symbolOffset);
NextGeneration(false /* deletedContent */);
// Handle undo.
TextTreeUndo.CreateInsertUndoUnit(this, symbolOffset, 1);
// Tell parent to update Logical Tree
LogicalTreeHelper.AddLogicalChild(parentLogicalNode, embeddedObject);
// Raise the public event.
// During document load we won't have listeners and we can save
// an allocation on every insert. This can easily save 1000's of allocations during boot.
if (this.HasListeners)
{
insertPosition = new TextPointer(this, objectNode, ElementEdge.BeforeStart);
AddChange(insertPosition, 1, 1, PrecursorTextChangeType.ContentAdded);
}
}