在Silverlight中,如果一个TextBox AcceptsReturn,所有的换行\ r,即使Environment.Newline是\ r \ñ。为什么是这样? (WPF有\ r \ N作为换行的文本框)
In silverlight, if a TextBox AcceptsReturn, all newlines are \r, even though Environment.Newline is \r\n. Why is this? (WPF has \r\n as newline for textbox)
我同意二滩的答案。我已经遇到了一个场景,这是造成不便。
I agree with ertan's answer. I have ran into a scenario in which this is inconveniencing.
我们有通过一个Silverlight文本框并存储从用户收集字符串数据的应用程序,在SQL Server数据库,这是一个非常普遍的数据。当存储的字符串数据预期线的应用程序中使用的其他组件休息,以重新通过 psented $ P $\ r \ N
A出现问题。这种成分的一个例子是Telerik的报表解决方案:请参阅换行问题,多行文本框的。
We have an application that collects string data from a user through a Silverlight Textbox and stores that data in a SQL Server database, which is a very common. A problem arises when other components of the application use that stored string data expecting line breaks to be represented by "\r\n"
. One example of such a component is Telerik's reporting solution: See Line break issue in multi line text boxes.
我用这个值转换器克服了这个问题:
I overcame this problem by using this value converter:
public class LineBreakCorrectionConverter : IValueConverter
{
private const string CR = "\r";
private const string CRLF = "\r\n";
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string text = value as string;
if (text == null)
return null;
return text.Replace(CRLF, CR);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string text = value as string;
if (text == null)
return null;
return text.Replace(CR, CRLF);
}
}