Dany Maor
Dany Maor

Reputation: 2411

Enable code collapsing on AvalonEdit control

I try to enable code collapsing on AvalonEdit control and I can not enable it properly.

public FoldingManager foldingManager;
public XmlFoldingStrategy foldingStrategy;

to enable code collapsing I insert this code on Window_Loaded

foldingManager = FoldingManager.Install(textEditor.TextArea);
foldingStrategy = new XmlFoldingStrategy();
foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);

and to update the collapsing I insert to textEditor_TextChanged this code

foldingStrategy.UpdateFoldings(foldingManager, textEditor.Document);

from the Window_Loaded I get only the first collapsing to work (like in the picture the other tags not updated)

the code in textEditor_TextChanged does not work at all

Code folding example

Upvotes: 2

Views: 2179

Answers (1)

Daniel
Daniel

Reputation: 16439

Your document is not a valid XML document: XML only allows one top-level element, but you have two (<head> and <body>).

XmlFoldingStrategy can therefore only fold the valid part of the document. If you want HTML folding, you'll need to write your own HtmlFoldingStrategy.

If you're OK with forcing the HTML to be valid XML, you'll have to add the opening <html> tag.

Upvotes: 3

Related Questions