public WolSettingsView() { InitializeComponent(); tbTryCount.Validation = EntryViewValidation.UShortValidation(min: 1); tbPort.Validation = EntryViewValidation.UShortValidation(); tbMac.Validation = (v) => { try { LanUtils.MacAddressParse(v.EntryView.Text); } catch { v.ErrorMessage = "МAC-адрес должен состоять из шести\r\nшестнадцатеричных чисел (от 00 до FF), разделенных двоеточием"; } }; tbMac.ErrorStateChanged += (o, args) => { var isError = args.Value.InputWrong; if (isError) { tbError.Text = args.Value.ErrorMessage; } else { tbError.Text = null; } ErrorStateChanged?.Invoke(isError); }; }
private void ReportStateChange(bool isInErrorState, string errorText = "") { _errorStatusText = errorText; _errorState = isInErrorState; if (ErrorStateChanged != null) { ErrorStateChanged.Invoke(this, null); } }
void RaiseErrorStateChanged() { ErrorStateChanged?.Invoke(this); }
private void NotifyErrorStateChanged(ErrorStateChangedEventArgs e) { ErrorStateChanged?.Invoke(e.AppendObject(this)); }
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); }; }
protected virtual void RaiseErrorChanged() { ErrorStateChanged?.Invoke(new ErrorStateChangedEventArgs(this)); }
public void SetError(string message) { Error = true; ErrorMessage = message; ErrorStateChanged?.Invoke(this); }
public void ClearError() { Error = false; ErrorMessage = ""; ErrorStateChanged?.Invoke(this); }