Reputation: 694
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
Upvotes: 4
Views: 10723
Reputation: 694
Its really Simple and Easy.
or Just right click on Project in Solution Explorer and Click Manage NuGet Packages, now click Online and Search Avalon Editor. Then Install AvalonEditor
Just add following code in xaml file.
xmlns:avalonedit="http://icsharpcode.net/sharpdevelop/avalonedit"
Now add your TextEditor as follow
<avalonedit:TextEditor SyntaxHighlighting="XML" x:Name="gameListXMLText" Height="200">
Now Just load xml file as follow
gameListXMLText.Text = File.ReadAllText("sample.xml");
Thats It :) Hip hip Hurrey :) Thanks Avalon
Upvotes: 3
Reputation: 10128
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.
Upvotes: 13