views:

334

answers:

4

We have a Silverlight application using the RichTextBox as a rich text editor for the user to create emails.

We actually have our own serializer but essentially we are saving and restoring the Xaml. As far as I can tell it is impossible to restore any text containing curly braces.

You can demonstrate this fairly easily by creating a RichTextBox and typing something similar to "{weird}" into it. Then take the .Xaml property of the textbox and set it on the .Xaml property of another textbox - kablooie.

As we have our own serializer I have tried escaping the Text member of the Run elements with "". This makes no difference. I've tried replacing the braces with { but that doesn't work either.

A: 

This sounds like a xml problem. Have you tried encapsulating your data in a CDATA block to encapsulate any special characters?

<richtext>

    <![CDATA[
    function matchwo(a,b)
    {
    if (a < b && a < 0) then
      {
      return 1;
      }
    else
      {
      return 0;
      }
    }
    ]]>

<richtext>
Jonathan Park
Putting the Run Text inside a CDATA block isn't supported by the Silverlight XamlReader unfortunately.
fuzzyman
+1  A: 

Acknowledging the issue here and checking with the team. If the Run starts with curly braces it appears to throw a value exception. I'm investigating.

Tim Heuer
A: 

A Silverlight developer has confirmed this as a bug. It happens if the Run Text starts with a '{' or a space followed by '{'. Because we have our own serializer I can insert a zero width space (&#8203;) at the start of every run which solves the problem.

fuzzyman
A: 

try escaping with {}{weird}(open and closed curly braces)

lee
Doesn't help (we tried that first - I should have mentioned it in the question). The problem is a bug in the Silverlight RichTextBox.
fuzzyman