在這裏看到了答案:
Newline in string attribute
你的情況,你需要做的寫一個轉換器(的東西,實現的IValueConverter)這是什麼打開包含\ r \ n爲進編碼實體字符串數據即 和 。然後在你的Binding上使用該轉換器。
public class EncodeCRLFConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string stringtoconvert = value as string;
if (input != null))
{
// Note there are different ways to do the replacement, this is
// just a very simplistic method.
stringtoconvert = stringtoconvert.Replace("\r", "
");
stringtoconvert = stringtoconvert.Replace("\n", "
");
return stringtoconvert;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}
在某處創建轉換器的實例...例如,通常在.Resources ....(在這個例子中,我剛剛使用了Window,因爲我不知道你的TextBlock在裏面)。
<Window.Resources>
<EncodeCRLFConverter x:Key="strconv"/>
<Window.Resources>
<TextBlock Height="Auto" TextWrapping="Wrap" Name="Blurb" Text="{Binding Bio, Converter={StaticResource strconv}}" />