I use this code to simulate the functionality of a tab in a silverlight application.
I would really like not to write this function many times, because it needs to be used on a fairly large number of text fields throughout the application. I created a static class
public static class TabInsert { private const string Tab = " "; public static void textBox_KeyDown(object sender, KeyEventArgs e) { TextBox textBox = sender as TextBox; if (e.Key == Key.Tab) { int selectionStart = textBox.SelectionStart; textBox.Text = String.Format("{0}{1}{2}", textBox.Text.Substring(0, textBox.SelectionStart), Tab, textBox.Text.Substring(textBox.SelectionStart + textBox.SelectionLength, (textBox.Text.Length) - (textBox.SelectionStart + textBox.SelectionLength)) ); e.Handled = true; textBox.SelectionStart = selectionStart + Tab.Length; } } }
so that I can access it from different places liek this textBox.KeyDown textBox.KeyDown += TabInsert.textBox_KeyDown;
Is there any way I can do this in XAML?
source share