前端
<Window
x:Class="WpfApp2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp2"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<Grid>
<TextBox Name="text1" UndoLimit="0" TextWrapping="NoWrap" />
Grid>
Window>
后台代码
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
text1.Text = "testasdfasdfgasd阿斯顿发斯蒂芬\r\n撒旦法师打发斯蒂芬\r\n阿斯顿发送到发送到\r\n";
}
}
这有什么办法解决吗 我需要不设定Wrap 且有时会直接赋值带有换行符的字符串
textbox加上属性AcceptsReturn="True"呢?
能从业务上处理吗?
因为换行符理论上应该是不需要输入的,可以在TextChanged事件中,对输入的文本进行处理,替换掉换行符
大多的解决思路是,中文输入崩溃解决思路:设置Textbox的UndoLimit 为0
这里有另外一个文章思路分享,提供你参考:http://t.zoukankan.com/jarvisniu-p-5511282.html
具体步骤为:
1、在窗口布局中加入一个WindowsFormsHost控件,设置Name(此处为host);
2、用代码在host中加入一个WinForm的Textbox:
host.Child = new System.Windows.Forms.TextBox();
我看已经解决了,就不写了,加油