views:

3147

answers:

5

Hi,

I am looking for a Silverlight text editor control that provides XML syntax highlighting. I found a few answers in Winforms or WPF, like here on Stackoverflow, but I didn't manage to convert them to Silverlight. The fact that Silverlight is missing System.Drawing is probably a big problem.

The only text editor I found for Silverlight is RichTextEdit on Codeplex, but I don't think it is a suitable base for real-time syntax highlighting.

Has anyone heard of such a control, or can provide hints on how to build one? Many thanks,

Romain

A: 

I thought this was an interesting question, but you've had no answer.

I don't know of an existing control.

I've built a control to edit XHTML, but it too uses System.Drawing rather than WPF (and therefore isn't for Silverlight).

WPF is probably at least as capable as System.Drawing, but I don't know it.

Hints on how I built it:

  • Define a DOM (a vanilla System.Xml.XmlDocument might suit you)
  • Parse a document to instantiate a DOM
  • Define a user control (with scroll bars)
  • Pass the DOM instance to the user control
  • In the control's 'paint' method, paint the visible fraction of the DOM
  • Implement support for mouse and key presses

If you really want hints on how to build one, ask something more specific.

ChrisW
A: 

Hi & thanks for your answer!

Unfortunately, while WPF has drawing capabilities, Silverlight runs a very restricted set of the CLR. Painting the user control looks like quite a difficult task.

However it has been done before with this Rich text editor for Silverlight. I will see if I manage to use similar techniques to render the XML document.

One question though: is the user control fast enough to render the DOM on the fly, as the user makes changes?

Gromix
+2  A: 

I finally found that control I was looking for! SL2TextBoxWsSynParser

EDIT: This control does not seem to be updated anymore, but a new syntax-highlighting control has surfaced:

It is available here, and used on the CoderProof website.

Gromix
+1  A: 

Actipro Software has a syntax highlighter component for Winforms, WPF, and Silverlight:

http://www.actiprosoftware.com/

chadbr
A: 

Hi Romain,

Check out our 100% native Silverlight SyntaxEditor code editor control. In the latest 2010.2 version, we released a new optional Web Languages Add-on that gives advanced editing functionality for XML, including: automated IntelliPrompt quick info tips, code outlining, end tag auto-complete, XML formatting, AST generation, and much more.

More details on the add-on are here: http://www.actiprosoftware.com/Products/DotNet/Silverlight/SyntaxEditor/Addons/Web/

And again, all this is written in pure Silverlight 4 code.

Actipro