Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF Richtextbox XamlWriter behaviour
    text
    copied!<p>I am trying to save some c# source code into the database. Basically I have a RichTextBox that users can type their code and save that to the database.</p> <p>When I copy and paste from the visual studio environment, I would like to preserve the formating etc. So I have chosen to save the FlowDocuments Xaml to the database and set this back to the RichTextBox.Document.</p> <p>My below two function serialise and deserialise the RTB's contents. </p> <pre><code> private string GetXaml(FlowDocument document) { if (document == null) return String.Empty; else{ StringBuilder sb = new StringBuilder(); XmlWriter xw = XmlWriter.Create(sb); XamlDesignerSerializationManager sm = new XamlDesignerSerializationManager(xw); sm.XamlWriterMode = XamlWriterMode.Expression; XamlWriter.Save(document, sm ); return sb.ToString(); } } private FlowDocument GetFlowDocument(string xamlText) { var flowDocument = new FlowDocument(); if (xamlText != null) flowDocument = (FlowDocument)XamlReader.Parse(xamlText); // Set return value return flowDocument; } </code></pre> <p>However when I try to serialise and deserialise the following code, I am noticing this incorrect(?) behaviour</p> <pre><code>using System; public class TestCSScript : MarshalByRefObject { } </code></pre> <p>Serialised XAML is</p> <p><code> using System; public class TestCSScript : MarshalByRefObject {}{ } </p> <p></code></p> <p>Notice the the new set of "{}"</p> <p>What am I doing wrong here... Thanks in advance for the help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload