文本框未读取扫描输入

textbox not reading scanned in input

我正在开发一个应用程序,它可以扫描条形码并将数据输入到 C# WPF 应用程序的文本框中。问题是当我扫描我的信息时,换行符消失了。我已经将相同的输入扫描到记事本和记事本++中,它们似乎显示换行符,但它没有出现在文本框中。我什至将文本框设为多行,但没有用。

我认为文本框过滤掉了我的字符。有什么办法可以让文本框不这样做吗?

期望的输出

the
cow
jumped
over
the
moon

实际输出

thecowjumpedoverthemoon

这是我的文本框代码

<TextBox x:Name="textbox_txt" TextWrapping="Wrap" AcceptsReturn="True" AcceptsTab="True" Margin="56,138,239.4,66.8" Background="White" AllowDrop="True" />

扫描的文本可能使用 Unix 风格的换行符 \n 而 windows 使用 \r\n。尝试:

var text = textbox_txt.Text.Replace("\n", "\r\n");

或者:

var text = textbox_txt.Text.Replace("\n", Environment.NewLine);

您分配给 TextBoxstring 似乎没有 \n 分开。 尝试使用 SringBuilder

StringBuild sb = new StringBuilder();
sb.AppendLine("the");
sb.AppendLine("cow");
sb.AppendLine("jumped");
sb.AppendLine("over");
sb.AppendLine("the");
sb.AppendLine("moon");
textbox_txt.Text = sb.Tostring();

我刚刚执行了您的示例,在您的用例中,您只需将扫描码附加到 sb