A Parser for Formatted Text in WPF / Silverlight
November 5th, 2010
I finally got round to implement on-the-fly text formatting for Sketchables, which will allow you to define text formatting while typing (similar to wikis or forum posts). Sketchables will parse such strings and format them on the fly for you:
the star renders *bold* text
I didnโt rely on regular expressions here, but wrote a simple forwarding parser to process markup text. As it makes a pretty neat tool, I extracted it into a little sample app that shows a possible use for it. The presented implementation just creates nested text blocks, but you should be able to easily adjust it to your needs.
Latest Update: 2010.11.07 โ Fixed issue with single character chunks.
I made a similar converter, only it uses a different (tag) syntax. It creates Runs and Spans. I also created an attached property called Inlines (with a TypeConverter) that allows you to bind directly to a TextBlock (e.g. from a view model), for example:
.
Look for FormattedTextConverter on http://wpfcontrib.codeplex.com/.
Very nice, Eli – I like the syntax! If I had seen this earlier, I could have stolen quite a bit from you ๐
Hi Philipp, That’s pretty neat. Nice and simple. I can see myself using this in the future.
Colin E.
Thanks Colin ๐
Hi Philipp very interesting work, when I hit to download the files, I get an page not found
Thanks
Nice one Philip…Can only dream of WPF these days… up to my neck in MVC in my spare time, still coming along nicely
Cheers, Sacha!
Hope we are going to see some MVC goodness soon ๐
@Yiannis
Thanks a lot for reporting the hiccup – should be fixed now ๐
@Philipp Sumi
Yeah man actually enjoying the JQuery
@Sacha – I feel quite comfi in XAML land.