为什么一个Silverlight文本框使用\ r代表换行,而不是Environment.Newline(\ r \ n)的? [英] Why does a Silverlight TextBox use \r for a newline instead of Environment.Newline (\r\n)?

查看:363
本文介绍了为什么一个Silverlight文本框使用\ r代表换行,而不是Environment.Newline(\ r \ n)的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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的报表解决方案:请参阅<一href="http://www.telerik.com/community/forums/reporting/telerik-reporting/line-break-issue-in-multi-line-text-boxes.aspx"相对=nofollow>换行问题,多行文本框的。

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);
    }
}

这篇关于为什么一个Silverlight文本框使用\ r代表换行,而不是Environment.Newline(\ r \ n)的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆