Download AvalonEdit syntax highlight definition from resource

I have an AvalonEdit text box and I want to turn on syntax highlighting. I have already created the .xshd file, and I have it in my project as a resource. Now, how can I apply it to my AvalonEdit window?

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

+3
source share
2 answers

use this:

System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.FileName.xshd"));
+3
source

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 WpfApp15and sql.

I have used Project > ... Properties > Resources > Add Resource > Add Existing File....

0
source

All Articles