void AdvancedTextBox_Loaded(object sender, RoutedEventArgs e) { AdvancedTextBox ftb = sender as AdvancedTextBox; Console.WriteLine("AdvancedTextBox_Loaded " + (ftb.Text.Length == 0)); ftb.IsBlur = ftb.Text.Equals(""); }
/// <summary> /// Used whenever the text box is clicked on to determine if the blur text should go away /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnBlurTextInvalidated(DependencyObject d, DependencyPropertyChangedEventArgs e) { Console.WriteLine("OnBlurTextInvalidated"); AdvancedTextBox atb = (AdvancedTextBox)d; atb.IsBlur = true; }
/// <summary> /// Event focus has been lost on the text box /// Used by the blur to place blur text back on (if the text box is empty) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AdvancedTextBox_LostFocus(object sender, RoutedEventArgs e) { AdvancedTextBox ftb = sender as AdvancedTextBox; if (!ftb.BlurText.Equals("") && ftb.Text.Equals("")) { Console.WriteLine("BLARG"); ftb.IsBlur = true; } }
/// <summary> /// Event when a key has been pressed. /// Used by the Numeric function to increase/decrease the value /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AdvancedTextBox_PreviewKeyUp(object sender, KeyEventArgs e) { Console.WriteLine("AdvancedTextBox_PreviewKeyUp"); AdvancedTextBox ftb = sender as AdvancedTextBox; if (ftb.IsNumeric) { if (e.Key == Key.Up) { int i = 0; if (!ftb.Text.Equals("")) { i = int.Parse(ftb.Text); } i++; if (i <= ftb.MaximumValue) { ftb.Text = i.ToString(); } if (i < ftb.MinimumValue) { ftb.Text = ftb.MinimumValue.ToString(); } } if (e.Key == Key.Down) { int i = 0; if (!ftb.Text.Equals("")) { i = int.Parse(ftb.Text); } i--; if (i >= ftb.MinimumValue) { ftb.Text = i.ToString(); } else { ftb.Text = ftb.MinimumValue.ToString(); } if (i > ftb.MaximumValue) { ftb.Text = ftb.MaximumValue.ToString(); } } } }
/// <summary> /// Event Keyboard is focused on text box /// Used by blur to remove blur text /// Used by Focus to select all text /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AdvancedTextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { Console.WriteLine("AdvancedTextBox_GotKeyboardFocus"); AdvancedTextBox ftb = sender as AdvancedTextBox; ftb.IsBlur = false; if (ftb.IsAdvancedFocus) { ftb.Focus(); string t = ftb.Text; ftb.Text = t; ftb.SelectAll(); ftb.Focus(); e.Handled = true; } }
/// <summary> /// Event when the mouse has clicked /// Used by the blur text remove any blur effects /// Used by the advanced focus to select all text /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AdvancedTextBox_PreviewMouseDown(object sender, MouseButtonEventArgs e) { Console.WriteLine("AdvancedTextBox_PreviewMouseDown"); AdvancedTextBox ftb = sender as AdvancedTextBox; ftb.IsBlur = false; if (ftb.IsAdvancedFocus) { ftb.Focus(); string t = ftb.Text; ftb.Text = t; ftb.SelectAll(); ftb.Focus(); e.Handled = true; } }
/// <summary> /// Event when text has been added /// Used by the Numeric check to see if the text is a valid number /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AdvancedTextBox_PreviewTextInput(object sender, TextCompositionEventArgs e) { Console.WriteLine("AdvancedTextBox_PreviewTextInput"); AdvancedTextBox ftb = sender as AdvancedTextBox; if (ftb.IsNumeric) { foreach (Char c in e.Text.ToCharArray()) { if (Char.IsNumber(c) || Char.IsControl(c)) { continue; } else { e.Handled = true; } } } }
/// <summary> /// Event focus is on the text box /// Used by the blur to hide the blur text /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void AdvancedTextBox_GotFocus(object sender, RoutedEventArgs e) { AdvancedTextBox ftb = sender as AdvancedTextBox; ftb.IsBlur = false; }