XML Syntax Highlight for WPF C#

c#, formatting, syntax, wpf, xml

Solution

You can use the AvalonEdit control

You can get it from nuGet: http://www.nuget.org/packages/AvalonEdit

See: http://www.codeproject.com/Articles/42490/Using-AvalonEdit-WPF-Text-Editor for a guide on how to use it.

This will give you XML syntax highlighting and will function as an editor - it's a bit quirky to set up but does work quite well in my experience. Just use `SyntaxHighlighting="XML"` in your XAML.

Problem

There is an RichTextBox in my application, in which I want to show XML from externhal .xml file. But I need to show nodes/attributes/Values/Comments everything in xml format color. I have gone through XML Highlight in RichTextBox Link as well. But Its not helpful for me. As I have less time to complete this task. So can I get any API or some already built code for this? I load XML as below ``` XmlDocument doc = new XmlDocument(); doc.Load("filepath.xml"); gameListXMLRichText.Document.Blocks.Clear(); gameListXMLRichText.AppendText(doc.InnerXml.ToString()); ``` Formatting from the above link have lots of issues. but I can't go through that as of now, because of time. So please help me on this. Thanks in Advance. Edit: As I have taken code from the link and applied the code on a simple xml. The result is looks like below But It should look like Only Proper color is required, for me. Proper formatting is not required. Code link is : http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-10-12-22-80/highlightRTF.txt

Original source

Related problems