问题
I have Rad Mask TextBox and a button. So user can enter any case into the text box. when button is clicked, I am fetching some record based on text and event I have to change the text to upper, trim and position the caret to end.
I noticed, if upper case is entered, I get all the scenario's but when lower case is entered the postion of cursor is pointed to beginning.
this is what I tried.
txtSearch.MaskedText = txtSearch.MaskedText.ToUpperInvariant().Trim();
txtSearch.SelectionOnFocus = SelectionOnFocus.CaretToEnd;
I really appreciate your help.
回答1:
SelectionStart has solved the requirement.
Dispatcher.BeginInvoke(() =>
{
if (txtSearch.MaskedText != null)
{
txtSearch.MaskedText = txtSearch.MaskedText.ToUpper();
txtSearch.SelectionStart = txtSearch.MaskedText.Length;
txtSearch.Focus();
}
});
来源:https://stackoverflow.com/questions/14817987/rad-mask-textbox-change-text-to-upper-and-position-cursor-at-end-of-the-text