将TextBlock.Text设置为包含<linebreak> </linebreak>的字符串

时间:2011-10-25 20:26:42

标签: silverlight xaml textblock line-breaks

我有一个字符串,我正在从数据库中读取并将其绑定到XAML(Silverlight应用程序)中的TextBlock控件。来自数据库的字符串已经包含字符串中的元素。示例字符串是:Microsoft's TechEd conference is the largest annual conference for introducing IT professionals and developers to currently shipping and near-term Microsoft technologies.<linebreak><linebreak>Designed for those who build, deploy or operate solutions based on Microsoft technologies.

当渲染字符串时,它显示为文本而不是换行符(空格)。如何在渲染文本时根据文本显示空格来获取TextBlock控件(或任何其他控件)?

1 个答案:

答案 0 :(得分:0)

在将字符串绑定到TextBlock之前,为什么不进行正则表达式匹配并替换字符串。

using System;
using System.Text.RegularExpressions;

public class Example
{
   static string ModifyInput(string strIn)
   {
      // Replace linebreak with spaces.
      return Regex.Replace(strIn, "\<linebreak\>", " ");
   }
}

或其他相似的东西