1
0
mirror of https://github.com/chylex/Discord-History-Tracker.git synced 2025-07-05 03:38:52 +02:00
Discord-History-Tracker/app/Desktop/Dialogs/TextBox/TextBoxItem.cs

40 lines
981 B
C#

using System;
using System.Collections;
using System.ComponentModel;
using PropertyChanged.SourceGenerator;
namespace DHT.Desktop.Dialogs.TextBox;
partial class TextBoxItem : INotifyDataErrorInfo {
public string Title { get; init; } = "";
public object? Item { get; init; } = null;
public Func<string, bool> ValidityCheck { get; init; } = static _ => true;
public bool IsValid => ValidityCheck(Value);
[Notify]
private string value = string.Empty;
private void OnValueChanged() {
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(nameof(Value)));
}
public IEnumerable GetErrors(string? propertyName) {
if (propertyName == nameof(Value) && !IsValid) {
yield return string.Empty;
}
}
public bool HasErrors => !IsValid;
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
}
sealed class TextBoxItem<T> : TextBoxItem {
public new T Item { get; }
public TextBoxItem(T item) {
this.Item = item;
base.Item = item;
}
}