public EntryView() { Background = new SolidColorBrush(Colors.Transparent); VerticalContentAlignment = System.Windows.VerticalAlignment.Center; HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left; Foreground = new SolidColorBrush(Colors.White); BorderThickness = new System.Windows.Thickness(0, 0, 0, 2); BorderBrush = new SolidColorBrush(Colors.SteelBlue); CaretBrush = new SolidColorBrush(Colors.SteelBlue); var ignoreTextChangedFlag = false; base.TextChanged += (o, e) => { if (ignoreTextChangedFlag) { return; } int caretIndex = CaretIndex; var text = Text; var validation = new EntryViewValidation(this); validation.InputString = text; try { Validation?.Invoke(validation); var oldErrorState = ErrorMessage; if (!string.IsNullOrEmpty(validation.ErrorMessage)) { ErrorMessage = validation.ErrorMessage; InputWrong = true; } else { ErrorMessage = null; InputWrong = false; } if (oldErrorState != ErrorMessage) { ErrorStateChanged?.Invoke(this, new EventsArgs <EntryView>(this)); } if (!string.IsNullOrEmpty(validation.OutputString)) { ignoreTextChangedFlag = true; Text = validation.OutputString; ignoreTextChangedFlag = false; CaretIndex = caretIndex; } _oldText = Text; TextChanged?.Invoke(this, new RoutedEventArgs()); } catch { ignoreTextChangedFlag = true; Text = _oldText; ignoreTextChangedFlag = false; CaretIndex = caretIndex; } if (validation.SelectAll) { SelectAll(); } validation.AfterValidation?.Invoke(this); }; }
public WindowTest() { InitializeComponent(); entryView.Validation = (s) => EntryViewValidation.UIntValidation().Invoke(s); }