chore: add avalonia DataValidationErrors demo.

This commit is contained in:
NaBian committed 2025-08-06 22:09:56 +08:00
1 parent 5de152b20e
commit aa67dea033
8 files changed
+246 -162

No files matched your search

@@ -0,0 +1,19 @@
using System.ComponentModel.DataAnnotations;
using CommunityToolkit.Mvvm.ComponentModel;
namespace HandyControlDemo.ViewModel;
public partial class InputElementDemoViewModel : ObservableValidator
{
[Required] [EmailAddress] [ObservableProperty] [NotifyDataErrorInfo]
private string? _email1;
[Required] [EmailAddress] [ObservableProperty] [NotifyDataErrorInfo]
private string? _email2;
[Required] [ObservableProperty] [NotifyDataErrorInfo]
private string? _text1;
[Required] [ObservableProperty] [NotifyDataErrorInfo]
private string? _text2;
}
@@ -3,13 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
namespace HandyControlDemo.ViewModel;
public class DemoViewModelBase<T> : ObservableObject
public partial class DemoViewModelBase<T> : ObservableObject
{
private IList<T> _dataList = [];
public IList<T> DataList
{
get => _dataList;
set => SetProperty(ref _dataList, value);
}
[ObservableProperty] private IList<T> _dataList = [];
}
@@ -19,9 +19,12 @@ public class ViewModelLocator
services.AddSingleton<DataService>();
services.AddTransient<MainViewModel>();
services.AddTransient<InputElementDemoViewModel>();
_serviceProvider = services.BuildServiceProvider();
}
public MainViewModel Main => _serviceProvider.GetService<MainViewModel>()!;
public InputElementDemoViewModel InputElementDemo => _serviceProvider.GetService<InputElementDemoViewModel>()!;
}