在旧文本之前将文本插入 WPF 文本框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11753013/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 04:48:11  来源:igfitidea点击:

Insert text into WPF textbox before the old text

c#wpftextbox

提问by Tarek Saied

how i can Insert text into WPF textboxbefore the old text

如何textbox在旧文本之前将文本插入 WPF

like old textthen i add text new text old text

就像old text然后我添加文本new text old text

回答by S3ddi9

you can use either

你可以使用

textbox.Text="my new text" + textbox.Text;

or

或者

 txtbox1.SelectionStart = 0;
 txtbox1.SelectedText = "my new text";

回答by Tigran

I think the easiest way is to use Binding Converterwhere you will get the changeddata and can convert it into format you want before assigning it to UI.

我认为最简单的方法是使用Binding Converter,您可以在其中获取更改后的数据,并在将其分配给 UI 之前将其转换为您想要的格式。

回答by Chris Amelinckx

@S3ddi9 For the second option here, you might need to do:

@S3ddi9 对于这里的第二个选项,您可能需要执行以下操作:

txtbox1.SelectionStart = 0;

txtbox1.SelectionLength = 0; //this was missing

txtbox1.SelectedText = "my inserted text at top";