Home > Silverlight, Sketchables, WPF > A Parser for Formatted Text in WPF / Silverlight

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.

 

image

Latest Update:  2010.11.07 – Fixed issue with single character chunks.

Download Sample Application


  1. November 6th, 2010 at 08:22 | #1

    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/.

  2. November 6th, 2010 at 08:28 | #2

    Very nice, Eli – I like the syntax! If I had seen this earlier, I could have stolen quite a bit from you ;)

  3. November 6th, 2010 at 11:34 | #3

    Hi Philipp, That’s pretty neat. Nice and simple. I can see myself using this in the future.

    Colin E.

  4. November 6th, 2010 at 13:26 | #4

    Thanks Colin :)

  5. Yiannis Alexopoulos (Qualco S.A.)
    November 10th, 2010 at 09:22 | #5

    Hi Philipp very interesting work, when I hit to download the files, I get an page not found

    Thanks

  6. November 10th, 2010 at 12:49 | #6

    Nice one Philip…Can only dream of WPF these days… up to my neck in MVC in my spare time, still coming along nicely

  7. November 10th, 2010 at 15:18 | #7

    Cheers, Sacha!
    Hope we are going to see some MVC goodness soon :)

  8. November 10th, 2010 at 15:19 | #8

    @Yiannis
    Thanks a lot for reporting the hiccup – should be fixed now :)

  9. November 11th, 2010 at 06:51 | #9

    @Philipp Sumi

    Yeah man actually enjoying the JQuery

  10. November 11th, 2010 at 21:34 | #10

    @Sacha – I feel quite comfi in XAML land.

  1. November 7th, 2010 at 09:39 | #1