I spent my day searching on the internet a solution to my problem without success … That seems simple enough in theory.
I have a RichTextBox in XAML.
I have in my database a field named “content” type “LongText”
I just want my database saves the contents of the RichTextBox with simple style (bold, italic, underline) and that I can call my database, fill my RichTextBox content stored in my database while keeping the style of the text.
After that, I’ll have to show these data as a blog but … must already successfully save and load data.
XAML :
<RichTextBox x:Name="nameTextEditor" TabIndex="2" Grid.Row="2" SpellCheck.IsEnabled="True">
C#
FlowDocument doc = new FlowDocument();
StringReader sr = new StringReader(monArticle.Content);
XmlReader xmlReader = XmlReader.Create(sr);
Section sec = XamlReader.Parse(monArticle.Content) as Section;
while (sec.Blocks.Count > 0)
{
var block = sec.Blocks.FirstBlock;
sec.Blocks.Remove(block);
doc.Blocks.Add(block);
}
nameTextEditor.Document = doc;
Don’t work with error :
“Exception XamlParseException”
“Données non valides au niveau racine. Ligne 1, position 1.”
This is not the only code I tried but I test without understanding a word … Why it is not so easy to “take the contents of the RichTextBox” and “send in my database”?!
Thanks for all help
Now send rtfString to the database.
To display it back in the richtext box: