我正在使用UWP开发SSH客户端,并且已经掌握了所有基础知识。我现在遇到的问题是,如果我运行一个输出回车而不转到新行的命令(例如进度条),则文本块不会替换当前行。它只是创造了一个新的。所以我最终得到一个输出,如:
Getting dependencies 5%
Getting dependencies 6%
Getting dependencies 7%
Getting dependencies 8%
Getting dependencies 9%
Getting dependencies 10%
Getting dependencies 11%
而不是一行更新自己。这是我的xaml:
<ScrollViewer>
<StackPanel x:Name="stack">
<TextBlock x:Name="oldconsole" TextWrapping="Wrap"/>
<TextBox x:Name="console" AcceptsReturn="True"/>
</StackPanel>
</Scrollviewer>
和我的c#:
//Called when I receive a new string
private async void WriteLine(string text)
{
oldconsole.Text = oldconsole.Text + text;
console.Text = "";
}
我尝试在WriteLine()
的开头添加以下行:
if(text.StartsWith("\r") && !text.Contains("\n"))
oldconsole.Text = oldconsole.Text.Remove(oldconsole.Text.LastIndexOf(Environment.NewLine));
但正如你猜测的那样,它完全混乱了。我该如何解决这个问题?