Silverlight TextBox,移动插入位置

Jer*_*dle 3 silverlight textbox behavior caret

我正在尝试为屏幕键盘制作TextBox行为,它可以更新文本框中的文本,但我不能让它集中文本框并在完成更新后将插入符移动到文本的末尾.

我尝试在两个命令中使用TextBox.Focus()和TextBox.Select()而没有运气.

谢谢你的时间

Avi*_* P. 6

从输入事件处理程序(即鼠标单击虚拟键)更改焦点将失败,因为鼠标向上事件(或键入)将焦点返回到原始元素.为了使其工作,您必须使用该Dispatcher对象将focus命令分派到以后的时间.

例:

Dispatcher.Invoke(new Action(() =>
{
    textBox1.Focus();
    textBox1.SelectionStart = textBox1.Text.Length;
    // or textBox1.Select(textBox1.Text.Length,0);
}), System.Windows.Threading.DispatcherPriority.Background);
Run Code Online (Sandbox Code Playgroud)