public static MarkupObject GetMarkupObjectFor (object instance, XamlDesignerSerializationManager manager) { if (instance == null || manager == null) throw new ArgumentNullException (); throw new NotImplementedException (); }
public static string SerializeObjectTree(object objectTree, XamlWriterMode expressionMode) { StringBuilder sb = new StringBuilder(); TextWriter writer = new StringWriter(sb); XmlTextWriter xmlWriter = null; try { // Create XmlTextWriter xmlWriter = new XmlTextWriter(writer); // Set serialization mode XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(xmlWriter); manager.XamlWriterMode = expressionMode; // Serialize System.Windows.Markup.XamlWriter.Save(objectTree, manager); } finally { if (xmlWriter != null) xmlWriter.Close(); } return sb.ToString(); }
internal ElementMarkupObject(object instance, XamlDesignerSerializationManager manager) { Debug.Assert(instance != null); _instance = instance; _context = new ElementObjectContext(this, null); _manager = manager; }
public static void Save(object obj, XamlDesignerSerializationManager manager) { if (obj == null || manager == null) { throw new ArgumentNullException(); } throw new NotImplementedException(); }
public static void Save(object obj, XamlDesignerSerializationManager manager) { SecurityHelper.DemandUnmanagedCode(); if (obj == null) { throw new ArgumentNullException("obj"); } if (manager == null) { throw new ArgumentNullException("manager"); } MarkupWriter.SaveAsXml(manager.XmlWriter, obj, manager); }
/// <summary> /// Save writes the xml respresentation /// for the given object instance using the /// given XmlTextWriter embedded in the manager. /// </summary> /// <param name="obj"> /// Object instance /// </param> /// <param name="manager"> /// Serialization Manager /// </param> /// <remarks> /// This API requires unmanaged code permission /// </remarks> public static void Save(object obj, XamlDesignerSerializationManager manager) { // Validate input arguments if (obj == null) { throw new ArgumentNullException("obj"); } if (manager == null) { throw new ArgumentNullException("manager"); } MarkupWriter.SaveAsXml(manager.XmlWriter, obj, manager); }
public static string Serialize(object toSerialize) { var settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineOnAttributes = true; settings.ConformanceLevel = ConformanceLevel.Fragment; var sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb, settings); var manager = new XamlDesignerSerializationManager(writer); manager.XamlWriterMode = XamlWriterMode.Expression; XamlWriter.Save(toSerialize, manager); return sb.ToString(); }
public static string ConvertToXaml(object ui) { var outstr = new System.Text.StringBuilder(); //this code need for right XML fomating var settings = new System.Xml.XmlWriterSettings(); settings.Indent = true; settings.OmitXmlDeclaration = true; var writer = System.Xml.XmlWriter.Create(outstr, settings); var dsm = new System.Windows.Markup.XamlDesignerSerializationManager(writer); //this string need for turning on expression saving mode dsm.XamlWriterMode = System.Windows.Markup.XamlWriterMode.Expression; System.Windows.Markup.XamlWriter.Save(ui, dsm); return(outstr.ToString()); }
public static void Initialise(string key) { if (null == resourceDictionary) { Uri uri = new Uri("LitDev;component/Themes/Generic.xaml", UriKind.Relative); resourceDictionary = (ResourceDictionary)Application.LoadComponent(uri); } string value = ""; if (!styles.TryGetValue(key, out value)) { Style templateStyle = (Style)resourceDictionary[key]; StringBuilder sb = new StringBuilder(); XmlWriter writer = XmlWriter.Create(sb); XamlDesignerSerializationManager mgr = new XamlDesignerSerializationManager(writer); mgr.XamlWriterMode = XamlWriterMode.Expression; XamlWriter.Save(templateStyle, mgr); value = sb.ToString(); styles[key] = value; } style = (Style)XamlReader.Parse(value); }
/// <summary> /// オブジェクトをシリアライズします。 /// </summary> /// <param name="obj">シリアライズするオブジェクトを指定します。</param> /// <returns>シリアライズ結果を返します。</returns> public static string SerializeByXamlWriter(this object obj) { var settings = new XmlWriterSettings(); // 出力時の条件 settings.Indent = true; settings.NewLineOnAttributes = false; // XML バージョン情報の出力を抑制する settings.ConformanceLevel = ConformanceLevel.Fragment; var sb = new StringBuilder(); XamlDesignerSerializationManager manager = null; using (var writer = XmlWriter.Create(sb, settings)) { manager = new XamlDesignerSerializationManager(writer); manager.XamlWriterMode = XamlWriterMode.Expression; System.Windows.Markup.XamlWriter.Save(obj, manager); } return sb.ToString(); }
public bool ShouldSerializeChild(XamlDesignerSerializationManager manager) { bool shouldSerialize = false; if (manager != null) { shouldSerialize = (manager.XmlWriter == null); } return shouldSerialize; }
public static void Save(Object obj, XamlDesignerSerializationManager manager) { }
public static void Save (object obj, XamlDesignerSerializationManager manager) { if (obj == null || manager == null) throw new ArgumentNullException (); throw new NotImplementedException (); }
internal FrameworkElementFactoryMarkupObject(FrameworkElementFactory factory, XamlDesignerSerializationManager manager) { Debug.Assert(factory != null); _factory = factory; _manager = manager; }
private void SerializeObjectTree(object objectTree) { TextWriter writer = new StreamWriter(_stream); XmlTextWriter xmlWriter = null; try { // Create XmlTextWriter xmlWriter = new XmlTextWriter(writer); // Set serialization mode var manager = new XamlDesignerSerializationManager(xmlWriter); // SerializeToRtf XamlWriter.Save(objectTree, manager); } finally { if (xmlWriter != null) xmlWriter.Close(); } }
public static string ExportToXaml(OutlinerDocument Document, MainWindow wnd) { FlowDocument wholeDocument = new FlowDocument(); wholeDocument.FontFamily = UVOutliner.Settings.DefaultFontFamily; wholeDocument.FontSize = UVOutliner.Settings.DefaultFontSize; List<OutlinerNote> linearList = new List<OutlinerNote>(); DocumentHelpers.GetLinearNotesList(Document.RootNode, linearList, false); double totalWidth = 0; for (int i = 0; i < Document.ColumnDefinitions.Count; i++) totalWidth += Document.ColumnDefinitions[i].Width; // just random if (totalWidth == 0) totalWidth = 300; Table table = new Table(); table.LineHeight = 1; table.Margin = new Thickness(0); table.Padding = new Thickness(0); wholeDocument.Blocks.Add(table); for (int i = 0; i < wnd.OutlinerTreeColumns.Count; i++) { int columnId = wnd.GetColumnIdByView(i); TableColumn column = new TableColumn(); column.Width = new GridLength(Document.ColumnDefinitions[columnId].Width / totalWidth, GridUnitType.Star); table.Columns.Add(column); } // add column headers if (Document.ColumnDefinitions.Count > 1) { TableRowGroup rowGroup = new TableRowGroup(); table.RowGroups.Add(rowGroup); TableRow row = new TableRow(); rowGroup.Rows.Add(row); for (int i = 0; i < wnd.OutlinerTreeColumns.Count; i++) { int columnId = wnd.GetColumnIdByView(i); row.Cells.Add(new TableCell(new Paragraph(new Run(Document.ColumnDefinitions[columnId].ColumnName)))); } } TableRowGroup mainRowGroup = new TableRowGroup(); table.RowGroups.Add(mainRowGroup); // add all other columns for (int i = 0; i < linearList.Count; i++) { TableRow tableRow = new TableRow(); OutlinerNote note = linearList[i]; if (note.IsEmpty) { tableRow.Cells.Add(new TableCell(new Paragraph())); mainRowGroup.Rows.Add(tableRow); continue; } for (int c = 0; c < wnd.OutlinerTreeColumns.Count; c++) { int columnId = wnd.GetColumnIdByView(c); FlowDocument flowDocument = linearList[i].Columns[columnId].ColumnData as FlowDocument; if (flowDocument == null) { tableRow.Cells.Add(new TableCell()); continue; } double indent = note.Level * 20; TableCell cell = new TableCell(); tableRow.Cells.Add(cell); Section section = XamlReader.Load(TransformFlowDocumentToSection(flowDocument)) as Section; if (section == null) continue; if (columnId != 0) cell.Blocks.Add(section); else { Table tbl = new Table(); tbl.LineHeight = 1; tbl.Margin = new Thickness(0); tbl.Padding = new Thickness(0); TableColumn c1 = new TableColumn(); c1.Width = new GridLength(indent + 20 + (Document.CheckboxesVisble ? 20 : 0), GridUnitType.Pixel); TableColumn c2 = new TableColumn(); c2.Width = new GridLength(1, GridUnitType.Auto); tbl.Columns.Add(c1); tbl.Columns.Add(c2); var tmpRowGroup = new TableRowGroup(); var tmpRow = new TableRow(); tmpRowGroup.Rows.Add(tmpRow); tbl.RowGroups.Add(tmpRowGroup); Paragraph para = new Paragraph(); para.Margin = new Thickness(indent, 0, 0, 0); AddImages(Document, note, para); tmpRow.Cells.Add(new TableCell(para)); tmpRow.Cells.Add(new TableCell(section)); cell.Blocks.Add(tbl); } } mainRowGroup.Rows.Add(tableRow); if (note.HasInlineNote) AddInlineNote(mainRowGroup.Rows, note); } MemoryStream outStream = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlWriter.Create(outStream, settings); XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer); XamlWriter.Save(wholeDocument, manager); outStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(outStream); return reader.ReadToEnd(); }
public static string ExportToXaml_MultiColumn(OutlinerDocument Document, MainWindow wnd) { FlowDocument wholeDocument = new FlowDocument(); wholeDocument.FontFamily = UVOutliner.Settings.DefaultFontFamily; wholeDocument.FontSize = UVOutliner.Settings.DefaultFontSize; List<OutlinerNote> linearList = new List<OutlinerNote>(); DocumentHelpers.GetLinearNotesList(Document.RootNode, linearList, false); double totalWidth = 0; for (int i = 0; i < Document.ColumnDefinitions.Count; i++) totalWidth += Document.ColumnDefinitions[i].Width; //temporary //pageWidth = totalWidth; // just random if (totalWidth == 0) totalWidth = 300; Table table = new Table(); table.LineHeight = 1; table.Margin = new Thickness(0); table.Padding = new Thickness(0); wholeDocument.Blocks.Add(table); for (int i = 0; i < wnd.OutlinerTreeColumns.Count; i++) { int columnId = wnd.GetColumnIdByView(i); TableColumn column = new TableColumn(); //column.Width = new GridLength(Document.ColumnDefinitions[columnId].Width * pageWidth / totalWidth, GridUnitType.Pixel); column.Width = new GridLength(Document.ColumnDefinitions[columnId].Width / totalWidth, GridUnitType.Star); //column.Width = new GridLength(0, GridUnitType.Auto); table.Columns.Add(column); } // add column headers if (Document.ColumnDefinitions.Count > 1) { TableRowGroup rowGroup = new TableRowGroup(); table.RowGroups.Add(rowGroup); TableRow row = new TableRow(); rowGroup.Rows.Add(row); for (int i = 0; i < wnd.OutlinerTreeColumns.Count; i++) { int columnId = wnd.GetColumnIdByView(i); row.Cells.Add(new TableCell(new Paragraph(new Run(Document.ColumnDefinitions[columnId].ColumnName)))); } } TableRowGroup mainRowGroup = new TableRowGroup(); table.RowGroups.Add(mainRowGroup); // add all other columns for (int i = 0; i < linearList.Count; i++) { TableRow tableRow = new TableRow(); OutlinerNote note = linearList[i]; if (note.IsEmpty) { tableRow.Cells.Add(new TableCell(new Paragraph())); mainRowGroup.Rows.Add(tableRow); continue; } for (int c = 0; c < wnd.OutlinerTreeColumns.Count; c++) { int columnId = wnd.GetColumnIdByView(c); FlowDocument flowDocument = linearList[i].Columns[columnId].ColumnData as FlowDocument; if (flowDocument == null) { tableRow.Cells.Add(new TableCell()); continue; } double indent = (Math.Max(0, note.Level - 1)) * 20; TableCell cell = new TableCell(); tableRow.Cells.Add(cell); Section section = XamlReader.Load(ExportToXaml_Printing.TransformFlowDocumentToSection(flowDocument)) as Section; if (section == null) continue; if (columnId != 0) cell.Blocks.Add(section); else { Paragraph para = new Paragraph(); para.Margin = new Thickness(indent, 0, 0, 0); Image expImage = new Image(); expImage.Margin = new Thickness(0, 2, 0, 0); expImage.Width = 14; expImage.Height = 14; expImage.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.NearestNeighbor); BitmapImage bImage = new BitmapImage(); if (note.SubNotes.Count == 0) bImage.UriSource = new Uri("pack://application:,,,/uv;component/res/bullet.png"); else { if (note.IsExpanded) bImage.UriSource = new Uri("pack://application:,,,/uv;component/res/node_expanded.png"); else bImage.UriSource = new Uri("pack://application:,,,/uv;component/res/node_collapsed.png"); } expImage.Source = bImage; expImage.Stretch = Stretch.None; para.Inlines.Add(expImage); if (Document.CheckboxesVisble) { Image checkBox = new Image(); checkBox.Margin = new Thickness(0, 2, 0, 0); checkBox.Width = 14; checkBox.Height = 14; checkBox.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.NearestNeighbor); var checkSource = new BitmapImage(); if (note.IsChecked == true) checkSource.UriSource = new Uri("pack://application:,,,/uv;component/res/checkbox_checked.png"); else checkSource.UriSource = new Uri("pack://application:,,,/uv;component/res/checkbox_unchecked.png"); checkBox.Source = checkSource; checkBox.Stretch = Stretch.None; para.Inlines.Add(checkBox); } Paragraph par = new Paragraph(); Figure fig1 = new Figure(); fig1.Margin = new Thickness(0); fig1.HorizontalAnchor = FigureHorizontalAnchor.PageLeft; fig1.Blocks.Add(para); Figure fig2 = new Figure(); fig2.Margin = new Thickness(0); fig2.HorizontalAnchor = FigureHorizontalAnchor.PageLeft; fig2.Blocks.Add(section); par.Inlines.Add(fig1); par.Inlines.Add(fig2); cell.Blocks.Add(par); } } mainRowGroup.Rows.Add(tableRow); if (note.HasInlineNote) ExportToXaml_Printing.AddInlineNote(mainRowGroup.Rows, note, true); } MemoryStream outStream = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); //settings.Indent = true; XmlWriter writer = XmlWriter.Create(outStream, settings); XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer); XamlWriter.Save(wholeDocument, manager); outStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(outStream); return reader.ReadToEnd(); }
internal static string ExportAsXAML_List(OutlinerDocument Document) { FlowDocument wholeDocument = new FlowDocument(); wholeDocument.FontFamily = UVOutliner.Settings.DefaultFontFamily; wholeDocument.FontSize = UVOutliner.Settings.DefaultFontSize; List newList = new List(); wholeDocument.Blocks.Add(newList); DumpRtfRecursively_List(newList, Document.RootNode); MemoryStream outStream = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlWriter.Create(outStream, settings); XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer); XamlWriter.Save(wholeDocument, manager); outStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(outStream); return reader.ReadToEnd(); }
public bool ShouldSerializeInlines(XamlDesignerSerializationManager manager) { return (_complexContent != null) && (manager != null) && (manager.XmlWriter == null); }
public bool ShouldSerializeResources (XamlDesignerSerializationManager manager) { throw new NotImplementedException (); }
public ElementPropertyBase(XamlDesignerSerializationManager manager) { _manager = manager; }
private static bool ShouldSerialize(PropertyDescriptor pd, object instance, XamlDesignerSerializationManager manager) { MethodInfo shouldSerializeMethod; object invokeInstance = instance; DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(pd); if (dpd != null && dpd.IsAttached) { Type ownerType = dpd.DependencyProperty.OwnerType; string propertyName = dpd.DependencyProperty.Name; string keyName = propertyName + "!"; if (!TryGetShouldSerializeMethod(new ShouldSerializeKey(ownerType, keyName), out shouldSerializeMethod)) { string methodName = "ShouldSerialize" + propertyName; shouldSerializeMethod = ownerType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsObject, null); if (shouldSerializeMethod == null) shouldSerializeMethod = ownerType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsManager, null); if (shouldSerializeMethod == null) shouldSerializeMethod = ownerType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsMode, null); if (shouldSerializeMethod == null) shouldSerializeMethod = ownerType.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsObjectManager, null); if (shouldSerializeMethod != null && shouldSerializeMethod.ReturnType != typeof(bool)) shouldSerializeMethod = null; CacheShouldSerializeMethod(new ShouldSerializeKey(ownerType, keyName), shouldSerializeMethod); } invokeInstance = null; // static method } else { if (!TryGetShouldSerializeMethod(new ShouldSerializeKey(instance.GetType(), pd.Name), out shouldSerializeMethod)) { Type instanceType = instance.GetType(); string methodName = "ShouldSerialize" + pd.Name; shouldSerializeMethod = instanceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsObject, null); if (shouldSerializeMethod == null) shouldSerializeMethod = instanceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsManager, null); if (shouldSerializeMethod == null) shouldSerializeMethod = instanceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsMode, null); if (shouldSerializeMethod == null) shouldSerializeMethod = instanceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, _shouldSerializeArgsObjectManager, null); if (shouldSerializeMethod != null && shouldSerializeMethod.ReturnType != typeof(bool)) shouldSerializeMethod = null; CacheShouldSerializeMethod(new ShouldSerializeKey(instanceType, pd.Name), shouldSerializeMethod); } } if (shouldSerializeMethod != null) { ParameterInfo[] parameters = shouldSerializeMethod.GetParameters(); if (parameters != null) { object[] args; if (parameters.Length == 1) { if (parameters[0].ParameterType == typeof(DependencyObject)) { args = new object[] { instance as DependencyObject }; } else if (parameters[0].ParameterType == typeof(XamlWriterMode)) { args = new object[] { manager.XamlWriterMode }; } else { args = new object[] { manager }; } } else args = new object[] { instance as DependencyObject, manager }; return (bool)shouldSerializeMethod.Invoke(invokeInstance, args); } } return pd.ShouldSerializeValue(instance); }
public static void Save(object obj, XamlDesignerSerializationManager manager) { // Must be in full trust SecurityHelper.DemandUnmanagedCode(); // Validate input arguments if (obj == null) { throw new ArgumentNullException("obj"); } if (manager == null) { throw new ArgumentNullException("manager"); } MarkupWriter.SaveAsXml(manager.XmlWriter, obj, manager); }
/// <summary> /// Saves the given canvas as XAML. /// </summary> /// <param name="Canvas">The canvas.</param> /// <param name="Indent">XML indention on or off.</param> /// <returns>A memory stream containing the encoded XAML.</returns> public static MemoryStream SaveAsXAML(this Canvas Canvas, Boolean Indent = true) { #region Initial checks if (Canvas == null) throw new ArgumentNullException("The given canvas must not be null!"); #endregion var MemoryStream = new MemoryStream(); var XAMLWriter = new XamlDesignerSerializationManager( XmlWriter.Create(MemoryStream, new XmlWriterSettings() { Indent = Indent }) ); XamlWriter.Save(Canvas, XAMLWriter); return MemoryStream; }
public bool ShouldSerializeInlines(XamlDesignerSerializationManager manager) { return manager != null && manager.XmlWriter == null; }
private static Style CloneStyle(Style style, Style newBasedOn) { var sb = new StringBuilder(); var writer = XmlWriter.Create(sb, new XmlWriterSettings { Indent = true, ConformanceLevel = ConformanceLevel.Fragment, OmitXmlDeclaration = true, NamespaceHandling = NamespaceHandling.OmitDuplicates, }); var mgr = new XamlDesignerSerializationManager(writer) { XamlWriterMode = XamlWriterMode.Expression }; XamlWriter.Save(style, mgr); var clonedStyle = (Style) XamlReader.Parse(sb.ToString()); clonedStyle.BasedOn = newBasedOn; return clonedStyle; }
public bool ShouldSerializeText(XamlDesignerSerializationManager manager) { return manager.XmlWriter == null; }
private static void OnBrailleDocumentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var thisControl = (TabContent)d; FlowDocument fdTarget = new FlowDocument(); FlowDocument fdSource = thisControl.TextBox.Document; StringBuilder sb = new StringBuilder(); using (XmlWriter xw = XmlWriter.Create(sb)) { XamlDesignerSerializationManager sm = new XamlDesignerSerializationManager(xw); sm.XamlWriterMode = XamlWriterMode.Expression; XamlWriter.Save(fdSource, sm); } string copyText = sb.ToString(); fdTarget = (FlowDocument)XamlReader.Parse(copyText); List<Inline> runs = fdTarget.Blocks.OfType<Paragraph>().Select(x => x.Inlines).SelectMany(x => x.Select(y => y)).ToList(); List<FontFamily> fonts = FontCollection.FontsCollection.Select(x => x.NormalFontValue).ToList(); foreach (var item in runs.Where(x => fonts.Contains(x.FontFamily) == false)) item.FontFamily = FontCollection.FontsCollection.FirstOrDefault().BrailleFontKey; foreach (FontCollection font in FontCollection.FontsCollection) foreach (var item in runs.Where(x => x.FontFamily == font.NormalFontValue)) item.FontFamily = font.BrailleFontKey; thisControl.BraileBox.Document = fdTarget; }
public bool ShouldSerializeResources(XamlDesignerSerializationManager manager) { // Verify Context Access VerifyAccess(); bool shouldSerialize = true; if (manager != null) { shouldSerialize = (manager.XmlWriter == null); } return shouldSerialize; }
public static string ExportToXaml_SingleColumn(OutlinerDocument Document, MainWindow wnd) { FlowDocument wholeDocument = new FlowDocument(); wholeDocument.FontFamily = UVOutliner.Settings.DefaultFontFamily; wholeDocument.FontSize = UVOutliner.Settings.DefaultFontSize; List<OutlinerNote> linearList = new List<OutlinerNote>(); DocumentHelpers.GetLinearNotesList(Document.RootNode, linearList, false); // add all other columns for (int i = 0; i < linearList.Count; i++) { OutlinerNote note = linearList[i]; if (note.IsEmpty) { wholeDocument.Blocks.Add(new Paragraph()); continue; } FlowDocument flowDocument = linearList[i].Columns[0].ColumnData as FlowDocument; if (flowDocument == null) continue; Section section = XamlReader.Load(ExportToXaml_Printing.TransformFlowDocumentToSection(flowDocument)) as Section; if (section == null) continue; double indent = (Math.Max(0, note.Level - 1)) * 20; Paragraph para = new Paragraph(); para.Margin = new Thickness(indent, 0, 0, 0); Image expImage = new Image(); expImage.Margin = new Thickness(0, 2, 0, 0); expImage.Width = 14; expImage.Height = 14; expImage.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.NearestNeighbor); BitmapImage bImage = new BitmapImage(); if (note.SubNotes.Count == 0) bImage.UriSource = new Uri("pack://application:,,,/uv;component/res/bullet.png"); else { if (note.IsExpanded) bImage.UriSource = new Uri("pack://application:,,,/uv;component/res/node_expanded.png"); else bImage.UriSource = new Uri("pack://application:,,,/uv;component/res/node_collapsed.png"); } expImage.Source = bImage; expImage.Stretch = Stretch.None; para.Inlines.Add(expImage); if (Document.CheckboxesVisble) { Image checkBox = new Image(); checkBox.Margin = new Thickness(0, 2, 0, 0); checkBox.Width = 14; checkBox.Height = 14; checkBox.SetValue(RenderOptions.BitmapScalingModeProperty, BitmapScalingMode.NearestNeighbor); var checkSource = new BitmapImage(); if (note.IsChecked == true) checkSource.UriSource = new Uri("pack://application:,,,/uv;component/res/checkbox_checked.png"); else checkSource.UriSource = new Uri("pack://application:,,,/uv;component/res/checkbox_unchecked.png"); checkBox.Source = checkSource; checkBox.Stretch = Stretch.None; para.Inlines.Add(checkBox); } Paragraph par = new Paragraph(); Figure fig1 = new Figure(); fig1.Margin = new Thickness(0); fig1.Padding = new Thickness(0); fig1.HorizontalAnchor = FigureHorizontalAnchor.PageLeft; fig1.Blocks.Add(para); Figure fig2 = new Figure(); fig2.Margin = new Thickness(0); fig2.Padding = new Thickness(0); fig2.HorizontalAnchor = FigureHorizontalAnchor.PageLeft; fig2.Blocks.Add(section); par.Inlines.Add(fig1); par.Inlines.Add(fig2); wholeDocument.Blocks.Add( new Section(par)); } MemoryStream outStream = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); //settings.Indent = true; XmlWriter writer = XmlWriter.Create(outStream, settings); XamlDesignerSerializationManager manager = new XamlDesignerSerializationManager(writer); XamlWriter.Save(wholeDocument, manager); outStream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(outStream); return reader.ReadToEnd(); }