本文介绍了UWP应用程序不读取换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个C#UWP应用程序,我注意到当我将其输入到文本框中时,输出文本中缺少换行符(\ n).当我按Enter进入文本框时,它会生成CR + LF字符(\ r \ n).我该怎么做才能使文本框的行为引起CR + LF和amp;如果.我已经设置了AcceptReturn ="true",我什至尝试用\ r \ n替换\ n,但这也不起作用.

解决方案

正如@lindexi所说,新的TextBox在Windows 10内部版本15063中将\r用作换行符. CR + LF和如果.您可以在KeyUp事件中以编程方式处理它.但是\n& \n\r将自动变为\r.

例如:

// original
MyTextBox.Text = "Nico Zhu \nzhuminghao\nwanglaoshi\r\n\rzhuzhuz\n";

// converted
MyTextBox.Text = "Nico Zhu \rzhuminghao\rwanglaoshi\r\rzhuzhuz\r"

有关更多信息,请参考提供意外结果的UWP TextBox控件. /p>

I am creating a C# UWP application and I have noticed that the line feed (\n) character is missing from the output text when I enter it into a Textbox. When I press enter into my Textbox it produces CR+LF character (\r\n). what can I do to bring the textbox behavior to notice both CR+LF & LF. I have set AcceptReturn = "true" and I have even tried replacing \n with \r\n but that doesn't work either.

解决方案

As @lindexi said the new TextBox used \r as line feed character in Windows 10 build 15063. If you want to bring the textbox behavior to notice both CR+LF & LF. You may handle it programmatically on KeyUp event. However the \n & \n\r will turn to \r automatically.

For example :

// original
MyTextBox.Text = "Nico Zhu \nzhuminghao\nwanglaoshi\r\n\rzhuzhuz\n";

// converted
MyTextBox.Text = "Nico Zhu \rzhuminghao\rwanglaoshi\r\rzhuzhuz\r"

For more please refer to UWP TextBox control giving unexpected results.

这篇关于UWP应用程序不读取换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:24