簡體   English   中英

在舊文本之前將文本插入WPF文本框

[英]Insert text into WPF textbox before the old text

我如何在舊文本之前將文本插入WPF textbox

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

你也可以使用

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

要么

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

我認為最簡單的方法是使用Binding Converter來獲取已更改的數據,並在將其分配給UI之前將其轉換為您想要的格式。

@ S3ddi9對於第二個選項,您可能需要這樣做:

txtbox1.SelectionStart = 0;

txtbox1.SelectionLength = 0; //this was missing

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM