1

I need to write XAML of a WPF control to string. I used XamlWriter.Save(). It works good. Also I need to format, indent and show the string in a editor (read only) like VS Xaml code view. I dont know how to do this.

Please share your valuable ideas.

WPF Lover
  • 299
  • 6
  • 16
  • Do you need to write this from scratch or are you willing/allowed to use 3rd party controls? – Emond May 23 '12 at 10:21

1 Answers1

2

You can save to a XmlWriter instance, create a XmlWriter, create a XmlWriterSettings instance and set the Indent property to true and set this on your XmlWriter. That way you should have the indentation.

Now for a control to display it, you could use the RichTextBox in wpf, or look for a custom control around the web.

dowhilefor
  • 10,971
  • 3
  • 28
  • 45
  • When I do this I get this strange namespace definition in the output: ``. But the original xaml file had the following namespace declarations: ` – bitbonk Mar 26 '13 at 22:46