本文整理汇总了C#中System.Windows.Documents.Paragraph类的典型用法代码示例。如果您正苦于以下问题:C# Paragraph类的具体用法?C# Paragraph怎么用?C# Paragraph使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Paragraph类属于System.Windows.Documents命名空间,在下文中一共展示了Paragraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ColorizeXAML
public static FlowDocument ColorizeXAML( string xamlText, FlowDocument targetDoc )
{
XmlTokenizer tokenizer = new XmlTokenizer();
XmlTokenizerMode mode = XmlTokenizerMode.OutsideElement;
List<XmlToken> tokens = tokenizer.Tokenize( xamlText, ref mode );
List<string> tokenTexts = new List<string>( tokens.Count );
List<Color> colors = new List<Color>( tokens.Count );
int position = 0;
foreach( XmlToken token in tokens )
{
string tokenText = xamlText.Substring( position, token.Length );
tokenTexts.Add( tokenText );
Color color = ColorForToken( token, tokenText );
colors.Add( color );
position += token.Length;
}
Paragraph p = new Paragraph();
// Loop through tokens
for( int i = 0; i < tokenTexts.Count; i++ )
{
Run r = new Run( tokenTexts[ i ] );
r.Foreground = new SolidColorBrush( colors[ i ] );
p.Inlines.Add( r );
}
targetDoc.Blocks.Add( p );
return targetDoc;
}
示例2: BindFeatures
private void BindFeatures(List<HalanVersionInfo> products)
{
foreach( HalanVersionInfo inf in products ) {
string title = string.Format("{0} {1}.{2:D2}", inf.Product.Replace("ServiceBusMQManager", "Service Bus MQ Manager"),
inf.LatestVersion.Major, inf.LatestVersion.Minor);
Paragraph para = new Paragraph();
para.Inlines.Add(new Bold(
new Run(title) { FontSize = 19 } ));
if( inf.ReleaseDate > DateTime.MinValue )
para.Inlines.Add( new Run(string.Concat(", Released: ", inf.ReleaseDate.ToShortDateString())) );
tbFeatures.Document.Blocks.Add(para);
var list = new System.Windows.Documents.List();
foreach( var f in inf.Features )
list.ListItems.Add( new ListItem(new Paragraph(new Run(f))) );
tbFeatures.Document.Blocks.Add(list);
if( !_url.IsValid() )
_url = inf.Url;
}
}
示例3: Bold
/// <summary>
/// This method returns a simple paragraph text of header.
/// </summary>
/// <param name="patternName">The name of pattern we want to display</param>
/// <param name="hitStart">Start position of our hit</param>
/// <param name="hitEnd">End position of our hit</param>
/// <returns>A paragraph of text for our header.</returns>
static public Paragraph GetRichHeader
(String patternName, int hitStart, int hitEnd)
{
// Create our bold header bold text.
Bold myBold = new Bold();
myBold.Inlines.Add("Sequence Hits Viewer");
Run myRun2 = new Run();
myRun2.Text = "================";
myRun2.Text += NEWLINE;
myRun2.Text += NEWLINE;
myRun2.Text += "Matched Start Position : [ " + hitStart + " ]";
myRun2.Text += NEWLINE;
myRun2.Text += "Matched End Position : [ " + hitEnd + " ]";
myRun2.Text += NEWLINE;
myRun2.Text += NEWLINE;
myRun2.Text += "================ " + patternName + " ================";
myRun2.Text += NEWLINE;
Paragraph Header = new Paragraph();
Header.Inlines.Add(myBold);
Header.Inlines.Add(myRun2);
return Header;
}
示例4: CreateDiffTextForDisplay
public Paragraph CreateDiffTextForDisplay(string diffText)
{
Paragraph diffParagraph = new Paragraph();
string[] lines = diffText.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.None);
foreach (string line in lines)
{
if (line.StartsWith("+"))
{
diffParagraph.Inlines.Add(new AddTextRun(line));
}
else if (line.StartsWith("-"))
{
diffParagraph.Inlines.Add(new DeleteTextRun(line));
}
else if (line.StartsWith("@@"))
{
diffParagraph.Inlines.Add(new LineBreak());
diffParagraph.Inlines.Add(new LineNumberTextRun(line));
}
else
{
diffParagraph.Inlines.Add(new Run(line));
}
diffParagraph.Inlines.Add(new LineBreak());
}
return diffParagraph;
}
示例5: ConversationRendererRichText
public ConversationRendererRichText(IDisplayOptionsReadOnly displayOptions, IConversation conversation)
: base(displayOptions, conversation)
{
_currentParagraph = null;
_fileSystem = new OsFileSystem();
}
示例6: cmdCreateDynamicDocument_Click
private void cmdCreateDynamicDocument_Click(object sender, RoutedEventArgs e)
{
// Create first part of sentence.
Run runFirst = new Run();
runFirst.Text = "Hello world of ";
// Create bolded text.
Bold bold = new Bold();
Run runBold = new Run();
runBold.Text = "dynamically generated";
bold.Inlines.Add(runBold);
// Create last part of sentence.
Run runLast = new Run();
runLast.Text = " documents";
// Add three parts of sentence to a paragraph, in order.
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(runFirst);
paragraph.Inlines.Add(bold);
paragraph.Inlines.Add(runLast);
// Create a document and add this paragraph.
FlowDocument document = new FlowDocument();
document.Blocks.Add(paragraph);
// Show the document.
docViewer.Document = document;
}
示例7: TraverseParagraph
/// <summary>
/// Traverses only passed paragraph
/// </summary>
/// <param name="p"></param>
public void TraverseParagraph(Paragraph p)
{
if (p.Inlines != null && p.Inlines.Count > 0)
{
Inline il = p.Inlines.FirstInline;
while (il != null)
{
Run r = il as Run;
if (r != null)
{
VisualVisited(this, r, true);
il = il.NextInline;
continue;
}
InlineUIContainer uc = il as InlineUIContainer;
if (uc != null && uc.Child != null)
{
VisualVisited(this, uc.Child, true);
il = il.NextInline;
continue;
}
Figure fg = il as Figure;
if (fg != null)
{
TraverseBlockCollection(fg.Blocks);
}
il = il.NextInline;
}
}
}
示例8: AddParagraph
public static Paragraph AddParagraph(this FlowDocument doc, string text)
{
var par = new Paragraph();
par.Inlines.Add(text);
doc.Blocks.Add(par);
return par;
}
示例9: ConvertTextDocumentToBlock
public static Block ConvertTextDocumentToBlock(TextDocument document, IHighlighter highlighter)
{
if (document == null)
throw new ArgumentNullException("document");
// Table table = new Table();
// table.Columns.Add(new TableColumn { Width = GridLength.Auto });
// table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
// TableRowGroup trg = new TableRowGroup();
// table.RowGroups.Add(trg);
Paragraph p = new Paragraph();
foreach (DocumentLine line in document.Lines) {
int lineNumber = line.LineNumber;
// TableRow row = new TableRow();
// trg.Rows.Add(row);
// row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
HighlightedInlineBuilder inlineBuilder = new HighlightedInlineBuilder(document.GetText(line));
if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
int lineStartOffset = line.Offset;
foreach (HighlightedSection section in highlightedLine.Sections)
inlineBuilder.SetHighlighting(section.Offset - lineStartOffset, section.Length, section.Color);
}
// Paragraph p = new Paragraph();
// row.Cells.Add(new TableCell(p));
p.Inlines.AddRange(inlineBuilder.CreateRuns());
p.Inlines.Add(new LineBreak());
}
return p;
}
示例10: CreateTemplateDocument
public static FlowDocument CreateTemplateDocument(string pattern, Dictionary<string, ParamValue> parameters, ArrayList lines)
{
FlowDocument document = new FlowDocument();
Paragraph paragraph = new Paragraph();
foreach (string line in lines)
{
MatchCollection matchReturn = Regex.Matches(line, pattern);
if (matchReturn.Count != 0)
{
int index = 0;
foreach (Match match in matchReturn)
{
paragraph.Inlines.Add(new Run(line.Substring(index, match.Index - index)));
index = match.Index + match.Length;
TextBlock textBlock = new TextBlock();
parameters[match.Value].TextControl.Add(textBlock);
textBlock.Text = parameters[match.Value].Value;
textBlock.Background = Brushes.Green;
paragraph.Inlines.Add(textBlock);
}
paragraph.Inlines.Add(new Run(line.Substring(index, line.Length - index)));
}
else
{
paragraph.Inlines.Add(new Run(line));
}
paragraph.Inlines.Add(new LineBreak());
}
document.Blocks.Add(paragraph);
return document;
}
示例11: ZTextBufferWindow
public ZTextBufferWindow(ZWindowManager manager, FontAndColorService fontAndColorService)
: base(manager, fontAndColorService)
{
this.normalFontFamily = new FontFamily("Cambria");
this.fixedFontFamily = new FontFamily("Consolas");
var zero = new FormattedText(
textToFormat: "0",
culture: CultureInfo.InstalledUICulture,
flowDirection: FlowDirection.LeftToRight,
typeface: new Typeface(normalFontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal),
emSize: this.FontSize,
foreground: Brushes.Black);
this.fontCharSize = new Size(zero.Width, zero.Height);
this.document = new FlowDocument
{
FontFamily = normalFontFamily,
FontSize = this.FontSize,
PagePadding = new Thickness(8.0)
};
this.paragraph = new Paragraph();
this.document.Blocks.Add(this.paragraph);
this.scrollViewer = new FlowDocumentScrollViewer
{
FocusVisualStyle = null,
Document = this.document
};
this.Children.Add(this.scrollViewer);
}
示例12: UpdateInlines
private void UpdateInlines()
{
if (this.HightlightedText == null || this.Text == null)
{
return;
}
var p = new Paragraph();
var parts = this.Text.Split(new[] { this.HightlightedText }, StringSplitOptions.None);
for (var i = 0; i < parts.Length; ++i)
{
if (i != 0)
{
p.Inlines.Add(new Run()
{
Text = this.HightlightedText,
Background = Brushes.Yellow,
});
}
p.Inlines.Add(new Run()
{
Text = parts[i],
Background = Brushes.Transparent,
});
}
this.TextBlock.Document = new FlowDocument(p);
}
示例13: parse
public Paragraph parse(string message)
{
Paragraph p = new Paragraph();
p.LineHeight = 1;
DateTime today = DateTime.Now;
p.Inlines.Add("(" + today.ToString("HH:mm:ss") + ") ");
int lastPos = 0;
foreach (Match match in _regexUrl.Matches(message.Replace(Environment.NewLine,"")))
{
if (match.Index != lastPos) {
// parse smileys before hyperlink
p = _smiley.insertSmileys(p, message.Substring(lastPos, match.Index - lastPos));
lastPos = match.Index + match.Length;
// parse hyperlink
Hyperlink textLink = new Hyperlink(new Run(match.Value));
textLink.NavigateUri = new Uri(match.Value);
textLink.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(_openHyperlink);
p.Inlines.Add(textLink);
lastPos = match.Index + match.Length;
}
}
// wenn text noch nicht zu ende, noch mal nach smileys schauen
p = _smiley.insertSmileys(p, message.Substring(lastPos));
return p;
}
示例14: Convert
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var text = value as string;
if (text == null) throw new ArgumentException("Value must be of type string.");
var fd = new FlowDocument();
var paragraph = new Paragraph();
var splitText = text.Split(' ');
foreach (var word in splitText)
{
Uri uri;
bool result = Uri.TryCreate(word, UriKind.Absolute, out uri) && uri.Scheme == Uri.UriSchemeHttp;
if (result)
{
var hl = new Hyperlink();
hl.Inlines.Add(uri.AbsoluteUri);
hl.NavigateUri = uri;
paragraph.Inlines.Add(hl);
paragraph.Inlines.Add(" ");
}
else
{
paragraph.Inlines.Add(word);
paragraph.Inlines.Add(" ");
}
}
fd.Blocks.Add(paragraph);
return fd;
}
示例15: Convert
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
{
var text = value as String;
var flowDocument = new FlowDocument();
if (String.IsNullOrEmpty(text))
return flowDocument;
var paragraph = new Paragraph();
using (var reader = new StringReader(text))
{
String line;
while ((line = reader.ReadLine()) != null)
{
if (line.StartsWith("+++") ||
line.StartsWith("---") ||
line.StartsWith("diff ", StringComparison.OrdinalIgnoreCase))
continue;
paragraph.Inlines.Add(BuildLine(line));
paragraph.Inlines.Add(new LineBreak());
}
}
return paragraph.Inlines;
}