WPF PasswordBox TextBox控件 光标移到最后
参考:
wpf passwordbox控件 光标移到最后
WPF学习笔记-TextBox光标位置如何放到最后?
PasswordBox
/// <summary> /// 设置光标位置 /// </summary> /// <param name="passwordBox"></param> /// <param name="start">光标开始位置</param> /// <param name="length">选中长度</param> private void SetSelection(PasswordBox passwordBox, int start, int length) { passwordBox.GetType() .GetMethod("Select", BindingFlags.Instance | BindingFlags.NonPublic) .Invoke(passwordBox, new object[] { start, length }); }
TextBox
TextBox.SelectionStart = TextBox.Text.Length;