Rad Mask TextBox: Change Text to upper and position cursor at end of the text.

荒凉一梦 提交于 2019-12-11 15:06:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!