Posts Tagged ‘WPF’

How to bring the cursor to the end of text in the textbox control – WPF C#

Normally if we focus a textbox control the cursor would be in the start of the textbox.But when there is text already in the textbox it would be annoying if the cursor is in start.It would be better if the cursor is at the end of content in texbox. Thus to position the cursor at the end of the text content of a textBox control,we have to call the select method and specify the selection start position to the length [...]

Make Textbox Number Only – WPF

Coding : private void txt_PreviewTextInput(object sender, TextCompositionEventArgs e) { e.Handled = !ValidNumeric(e.Text); base.OnPreviewTextInput(e); }   bool ValidNumeric(string str) { bool ret = true;   int l = str.Length; for (int i = 0; i < l; i++) { char ch = str[i]; ret &= Char.IsDigit(ch); }   return ret; } Thanks dedjo