Created
July 23, 2020 11:08
-
-
Save poqdavid/e787217784a0a7c2b948c0893ccf4c73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ParagraphExtention | |
{ | |
public static void Append(this Paragraph paragraph, string value = "", Brush background = null, Brush foreground = null, bool bold = false, bool italic = false, bool underline = false, bool waitUntilReturn = false) | |
{ | |
Action append = () => | |
{ | |
Inline run = new Run(value); | |
if (background != null) run.Background = background; | |
if (foreground != null) run.Foreground = foreground; | |
if (bold) run = new Bold(run); | |
if (italic) run = new Italic(run); | |
if (underline) run = new Underline(run); | |
paragraph.Inlines.Add(run); | |
paragraph.Inlines.Add(run); | |
}; | |
if (paragraph.CheckAccess()) | |
{ | |
append(); | |
} | |
else if (waitUntilReturn) | |
{ | |
paragraph.Dispatcher.Invoke(append); | |
} | |
else | |
{ | |
paragraph.Dispatcher.BeginInvoke(append); | |
} | |
} | |
} | |
public static class RichTextBoxExtensions | |
{ | |
public static void CheckAppendText(this RichTextBox richtextBox, Paragraph msg, bool waitUntilReturn = false) | |
{ | |
//Action append = () => | |
Action append = () => | |
{ | |
richtextBox.Document.CheckAppendText(msg); | |
}; | |
if (richtextBox.CheckAccess()) | |
{ | |
append(); | |
} | |
else if (waitUntilReturn) | |
{ | |
richtextBox.Dispatcher.Invoke(append); | |
} | |
else | |
{ | |
richtextBox.Dispatcher.BeginInvoke(append); | |
} | |
} | |
} | |
public static class FlowDocumentExtensions | |
{ | |
public static void CheckAppendText(this FlowDocument fDoc, Paragraph msg, bool waitUntilReturn = false) | |
{ | |
//Action append = () => | |
Action append = () => | |
{ | |
//Paragraph msgx = msg; | |
// msgx.Inlines.Add(Environment.NewLine); | |
fDoc.Blocks.Add(msg); | |
}; | |
if (fDoc.CheckAccess()) | |
{ | |
append(); | |
} | |
else if (waitUntilReturn) | |
{ | |
fDoc.Dispatcher.Invoke(append); | |
} | |
else | |
{ | |
fDoc.Dispatcher.BeginInvoke(append); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment