本文整理汇总了C#中System.Windows.Documents.TextElement类的典型用法代码示例。如果您正苦于以下问题:C# TextElement类的具体用法?C# TextElement怎么用?C# TextElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextElement类属于System.Windows.Documents命名空间,在下文中一共展示了TextElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Insert
public void Insert (TextElement element)
{
if (element == null)
throw new ArgumentNullException ("element");
NativeMethods.text_selection_insert (native, element.native);
}
示例2: CreateComponent
public Component CreateComponent(TextElement textElement)
{
var elementType = textElement.GetType();
var title = elementType.Name;
if (elementType == typeof(Paragraph))
{
return new ParagraphComponent(title, textElement as Paragraph);
}
if (elementType == typeof(Volume))
{
return new VolumeComponent(title, textElement as Volume);
}
if (elementType == typeof(Section))
{
return new SectionComponent(title, textElement as Section);
}
if (elementType == typeof(Run))
{
return new RunComponent(title, textElement as Run);
}
throw new NotSupportedException(string.Format("Not supported type {0}.", elementType));
}
示例3: ApplyFormatToTextElement
public void ApplyFormatToTextElement(TextElement e)
{
e.FontFamily = FontFamily;
e.FontSize = FontSize;
e.FontStyle = FontStyle;
e.FontWeight = FontWeight;
e.FontStretch = FontStretch;
if (ForegroundColor!=Colors.Black) e.Foreground = new SolidColorBrush(ForegroundColor);
if (BackgroundColor!=Colors.White) e.Background = new SolidColorBrush(BackgroundColor);
}
示例4: AddItem
private static void AddItem(TreeViewItem item, TextElement textElement)
{
TreeViewItem childItem;
if (textElement is InlineUIContainer)
{
childItem = new TreeViewItem
{
Header = ((InlineUIContainer) textElement).Child.GetType().Name,
IsExpanded = true
};
item.Items.Add(childItem);
}
else if (textElement is BlockUIContainer)
{
childItem = new TreeViewItem
{
Header = ((BlockUIContainer) textElement).Child.GetType().Name,
IsExpanded = true
};
item.Items.Add(childItem);
}
else if (textElement is Span)
{
AddCollection(item, ((Span) textElement).Inlines);
}
else if (textElement is Paragraph)
{
AddCollection(item, ((Paragraph) textElement).Inlines);
}
else if (textElement is List)
{
AddCollection(item, ((List) textElement).ListItems);
}
else if (textElement is ListItem)
{
AddCollection(item, ((ListItem) textElement).Blocks);
}
else if (textElement is Table)
{
TableTreeView(item, textElement as Table);
}
else if (textElement is AnchoredBlock)
{
var floater = textElement as Floater;
AddCollection(item, ((AnchoredBlock) textElement).Blocks);
}
//The element should be an inline (Run); try to display the text.
else if (textElement is Inline)
{
var range = new TextRange(((Inline) textElement).ContentEnd, ((Inline) textElement).ContentStart);
item.Header = item.Header + " - [" + range.Text + "]";
}
}
示例5: InsertElementClone
// -------------------------------------------------------------------
//
// Internal Methods
//
// -------------------------------------------------------------------
#region Internal Methods
internal static TextElement InsertElementClone(TextPointer start, TextPointer end, TextElement element)
{
TextElement newElement = (TextElement)Activator.CreateInstance(element.GetType());
// Copy properties to the newElement
newElement.TextContainer.SetValues(newElement.ContentStart, element.GetLocalValueEnumerator());
newElement.Reposition(start, end);
return newElement;
}
示例6: FormatText
private static void FormatText(TextElement text, TokenType tokenType)
{
if (tokenType == TokenType.WordForm)
{
FlowDocumentStyles.FormatWordForm(text);
}
else if (tokenType == TokenType.Example)
{
FlowDocumentStyles.FormatExample(text);
}
else
{
FlowDocumentStyles.FormatTranslation(text);
}
}
示例7: CreatePropertyUndoUnit
// Adds a TextTreePropertyUndoUnit to the open parent undo unit, if any.
// Called by TextElement's property change listener.
internal static void CreatePropertyUndoUnit(TextElement element, DependencyPropertyChangedEventArgs e)
{
UndoManager undoManager;
PropertyRecord record;
TextContainer textContainer = element.TextContainer;
undoManager = GetOrClearUndoManager(textContainer);
if (undoManager == null)
return;
record = new PropertyRecord();
record.Property = e.Property;
record.Value = e.OldValueSource == BaseValueSourceInternal.Local ? e.OldValue : DependencyProperty.UnsetValue;
undoManager.Add(new TextTreePropertyUndoUnit(textContainer, element.TextElementNode.GetSymbolOffset(textContainer.Generation) + 1, record));
}
示例8: TextFormat
public TextFormat(TextElement e)
{
FontFamily = e.FontFamily;
FontSize = e.FontSize;
FontStyle = e.FontStyle;
FontWeight = e.FontWeight;
FontStretch = e.FontStretch;
if (e.Foreground is SolidColorBrush)
{
ForegroundColor = ((SolidColorBrush)e.Foreground).Color;
}
else
{
ForegroundColor = SystemColors.WindowTextColor;
}
if (e.Background is SolidColorBrush)
{
BackgroundColor = ((SolidColorBrush)e.Background).Color;
}
else
{
BackgroundColor = SystemColors.WindowColor;
}
}
示例9: PasteNonMergeableTextFragment
// Helper for PasteTextFragment
private static void PasteNonMergeableTextFragment(TextElement fragment, TextRange range)
{
// We cannot split Hyperlink or other non-splittable inline ancestor.
// Paste text content of fragment in such case.
// Get text content to be pasted.
string fragmentText = TextRangeBase.GetTextInternal(fragment.ElementStart, fragment.ElementEnd);
// Paste text into our empty target range.
//
range.Text = fragmentText;
// Select pasted content
range.Select(range.Start, range.End);
}
示例10: PasteTextFragment
private static void PasteTextFragment(TextElement fragment, TextRange range)
{
Invariant.Assert(range.IsEmpty, "range must be empty at this point - emptied by a caller");
Invariant.Assert(fragment is Section || fragment is Span, "The wrapper element must be a Section or Span");
// Define insertion position.
TextPointer insertionPosition = TextRangeEditTables.EnsureInsertionPosition(range.End);
// Check if our insertion position has a non-splittable Inline ancestor such as Hyperlink element.
// Since we cannot split such Inline, we must switch to Text mode for pasting.
// Note that this also has the side effect of converting paragraph breaks to space characters.
if (insertionPosition.HasNonMergeableInlineAncestor)
{
PasteNonMergeableTextFragment(fragment, range);
}
else
{
PasteMergeableTextFragment(fragment, range, insertionPosition);
}
}
示例11: PasteSingleEmbeddedElement
// .............................................................
//
// Pasting
//
// .............................................................
// Handles a special case for pasting a single embedded element -
// needs to choose between BlockUIContainer and InlineUIContainer.
private static bool PasteSingleEmbeddedElement(TextRange range, TextElement fragment)
{
if (fragment.ContentStart.GetOffsetToPosition(fragment.ContentEnd) == 3)
{
TextElement uiContainer = fragment.ContentStart.GetAdjacentElement(LogicalDirection.Forward) as TextElement;
FrameworkElement embeddedElement = null;
if (uiContainer is BlockUIContainer)
{
embeddedElement = ((BlockUIContainer)uiContainer).Child as FrameworkElement;
if (embeddedElement != null)
{
((BlockUIContainer)uiContainer).Child = null;
}
}
else if (uiContainer is InlineUIContainer)
{
embeddedElement = ((InlineUIContainer)uiContainer).Child as FrameworkElement;
if (embeddedElement != null)
{
((InlineUIContainer)uiContainer).Child = null;
}
}
if (embeddedElement != null)
{
range.InsertEmbeddedUIElement(embeddedElement);
return true;
}
}
return false;
}
示例12: SetStyle
/// <summary>
/// The set style.
/// </summary>
/// <param name="run">
/// The run.
/// </param>
/// <param name="s">
/// The s.
/// </param>
private static void SetStyle(TextElement run, ParagraphStyle s)
{
run.FontFamily = new FontFamily(s.FontFamily);
run.FontSize = s.FontSize;
run.FontWeight = s.Bold ? FontWeights.Bold : FontWeights.Normal;
FontStyle fontStyle = FontStyles.Normal;
if (s.Italic)
{
fontStyle = FontStyles.Italic;
}
run.FontStyle = fontStyle;
}
示例13: GetICHFromFlowDocument
//-------------------------------------------------------------------
//
// Private Methods
//
//-------------------------------------------------------------------
#region Private Methods
/// <summary>
/// Given a ContentElement within FlowDocument searches for associated IContentHost.
/// </summary>
/// <param name="contentElement">Content element</param>
/// <param name="flowDocument">FlowDocument hosting ContentElement.</param>
/// <returns>Associated IContentHost with ContentElement.</returns>
private static IContentHost GetICHFromFlowDocument(TextElement contentElement, FlowDocument flowDocument)
{
IContentHost ich = null;
List<DocumentPageView> pageViews;
ITextView textView = flowDocument.StructuralCache.TextContainer.TextView;
if (textView != null)
{
// If FlowDocument is hosted by FlowDocumentScrollViewer, the RenderScope
// is FlowDocumentView object which hosts PageVisual representing the content.
// This PageVisual is also IContentHost for the entire content of DocumentPage.
if (textView.RenderScope is FlowDocumentView) // FlowDocumentScrollViewer
{
if (VisualTreeHelper.GetChildrenCount(textView.RenderScope) > 0)
{
ich = VisualTreeHelper.GetChild(textView.RenderScope, 0) as IContentHost;
}
}
// Our best guess is that FlowDocument is hosted by DocumentViewerBase.
// In this case search the style for all DocumentPageViews.
// Having collection of DocumentPageViews, find for the one which hosts TextElement.
else if (textView.RenderScope is FrameworkElement)
{
pageViews = new List<DocumentPageView>();
FindDocumentPageViews(textView.RenderScope, pageViews);
for (int i = 0; i < pageViews.Count; i++)
{
if (pageViews[i].DocumentPage is FlowDocumentPage)
{
textView = (ITextView)((IServiceProvider)pageViews[i].DocumentPage).GetService(typeof(ITextView));
if (textView != null && textView.IsValid)
{
// Check if the page contains ContentElement. Check Start and End
// position, which will give desired results in most of the cases.
// Having hyperlink spanning more than 2 pages is not very common,
// and this code will not work with it correctly.
if (textView.Contains(contentElement.ContentStart) ||
textView.Contains(contentElement.ContentEnd))
{
ich = pageViews[i].DocumentPage.Visual as IContentHost;
}
}
}
}
}
}
return ich;
}
示例14: FormatTranslation
public static void FormatTranslation(TextElement text)
{
text.Foreground = Brushes.Black;
text.FontStyle = FontStyles.Normal;
text.FontWeight = FontWeights.Normal;
}
示例15: AdjustFragmentForTargetRange
// Helper function used to set default value for an indicator requesting to merge last paragraph.
private static void AdjustFragmentForTargetRange(TextElement fragment, TextRange range)
{
if (fragment is Section && ((Section)fragment).HasTrailingParagraphBreakOnPaste)
{
// Explicit indicator is missing, we need to set it by default.
// In a case of TextRange.Xml property assignment we assume that
// user expects to insert as many paragraphs new paragraphs as her pasted xaml contains.
// The expection must be done to the case when the target range is
// extended beyond the last paragraph - then we must merge last paragraph
// to avoid extra paragraph creation at the end (one additional paragraph
// will be created in this case by Pasting code before pasting).
// The other case for exception is when target TextContainer is empty -
// in this case we as well want to merge last paragraph with the following
// one (which will be created as part of paragraph enforcement in pasting operation).
// The both desired conditions - IsAfterLastParagraph and "in empty container"
// can be identified by the following simple test - range.End is not at end-of-doc.
((Section)fragment).HasTrailingParagraphBreakOnPaste = range.End.GetPointerContext(LogicalDirection.Forward) != TextPointerContext.None;
}
}