Silverlight 4 RichTextBox - can't restore Xaml with text containing curly braces

偶尔善良 提交于 2019-12-11 09:45:26

问题


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 <Run Text="{} the real {Text} here" />. This makes no difference. I've tried replacing the braces with &#123; but that doesn't work either.


回答1:


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.




回答2:


This issue also occurs in the Windows Phone 7 (Mango) RichTextBox. I found a workaround here which consists of putting a zero-width non-joiner &#8204; character at the beginning and end of each Run. As opposed to using the zero-width space this also works if you have an opening curly brace at the beginning and a closing curly brace at the end.




回答3:


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>



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/2999782/silverlight-4-richtextbox-cant-restore-xaml-with-text-containing-curly-braces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!