public static void DisplayErrorInEditor(Exception e, FlowDocument target) { errorTemplate.Blocks.Add(new Paragraph(new Run() { Text = e.Message })); CopyTwoFlowDocument.Copy(errorTemplate, target); errorTemplate.Blocks.Remove(errorTemplate.Blocks.LastBlock); }
public void SetText(FlowDocument document, string text) { try { // if text is empty, then it is trying to renew string if (string.IsNullOrEmpty(text)) { document.Blocks.Clear(); return; } // each flowdocument owns block. The only way is to copy them though it's very inefficient FlowDocument parsed = XamlReader.Parse(text) as FlowDocument; CopyTwoFlowDocument.Copy(parsed, document); }catch (Exception e) // throw every parsed error out { throw e; } }