3

I have an AvalonEdit text box, and I want to include syntax highlighting. I've already created my .xshd file, and I have it in my project as a Resource. Now how do I apply it to my AvalonEdit box?

I've looked through a bunch of tutorials, but none of them have the solution.

Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
Entity
  • 7,972
  • 21
  • 79
  • 122

2 Answers2

3

use this:

System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.FileName.xshd"));
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
1

Another way, that worked for me:

using (var stream = new MemoryStream(WpfApp15.Properties.Resources.sql))
    {
        using (var reader = new System.Xml.XmlTextReader(stream))
        {
            this.AvalonQuery.SyntaxHighlighting =
                ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(reader,
                    ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance);
        }
    }

You need to change WpfApp15 and sql.

I've used Project > ... Properties > Resources > Add Resource > Add Existing File....

Masood Lapeh
  • 196
  • 3
  • 7