1
0
mirror of https://github.com/chylex/Discord-History-Tracker.git synced 2025-08-16 09:31:40 +02:00
Files
.github
.idea
app
.idea
Desktop
Common
Dialogs
CheckBox
File
Message
Progress
TextBox
TextBoxDialog.axaml
TextBoxDialog.axaml.cs
TextBoxDialogModel.cs
TextBoxItem.cs
Discord
Main
Resources
Server
App.axaml
App.axaml.cs
Arguments.cs
Desktop.csproj
Program.cs
Resources
Server
Utils
.editorconfig
.gitignore
Directory.Build.props
DiscordHistoryTracker.sln
NuGet.Config
Version.cs
build.sh
build.wsl.sh
empty.dht
global.json
tools
web
.gitattributes
.gitignore
LICENSE.md
README.md

48 lines
1.2 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using PropertyChanged.SourceGenerator;
namespace DHT.Desktop.Dialogs.TextBox;
partial class TextBoxDialogModel {
public string Title { get; init; } = "";
public string Description { get; init; } = "";
private IReadOnlyList<TextBoxItem> items = [];
public IReadOnlyList<TextBoxItem> Items {
get => items;
protected set {
foreach (TextBoxItem item in items) {
item.ErrorsChanged -= OnItemErrorsChanged;
}
items = value;
foreach (TextBoxItem item in items) {
item.ErrorsChanged += OnItemErrorsChanged;
}
}
}
[DependsOn(nameof(Items))]
public bool HasErrors => Items.Any(static item => !item.IsValid);
private void OnItemErrorsChanged(object? sender, DataErrorsChangedEventArgs e) {
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Items)));
}
}
sealed class TextBoxDialogModel<T> : TextBoxDialogModel {
private new IReadOnlyList<TextBoxItem<T>> Items { get; }
public IEnumerable<TextBoxItem<T>> ValidItems => Items.Where(static item => item.IsValid);
public TextBoxDialogModel(IEnumerable<TextBoxItem<T>> items) {
this.Items = new List<TextBoxItem<T>>(items);
base.Items = this.Items;
}
}