csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
using System;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using MiniMvvm;
|
|
|
|
namespace ControlCatalog.ViewModels;
|
|
|
|
public class DataValidationViewModel : ViewModelBase
|
|
{
|
|
private string? _DataAnnotationsSample;
|
|
|
|
[Required]
|
|
[EmailAddress]
|
|
[MinLength(5)]
|
|
public string? DataAnnotationsSample
|
|
{
|
|
get => _DataAnnotationsSample;
|
|
set => RaiseAndSetIfChanged(ref _DataAnnotationsSample, value);
|
|
}
|
|
|
|
public Func<object, object> Converter { get; } = new Func<object, object>(o =>
|
|
{
|
|
return $"Error: {o}";
|
|
});
|
|
|
|
|
|
private string? _ExceptionInsideSetterSample;
|
|
|
|
public string? ExceptionInsideSetterSample
|
|
{
|
|
get => _ExceptionInsideSetterSample;
|
|
set
|
|
{
|
|
if (value is null || value.Length < 5)
|
|
throw new ArgumentOutOfRangeException(nameof(value), "Give me 5 or more letter please :-)");
|
|
|
|
RaiseAndSetIfChanged(ref _ExceptionInsideSetterSample, value);
|
|
}
|
|
}
|
|
|
|
public Func<object, object> ExceptionConverter { get; } = new Func<object, object>(o =>
|
|
{
|
|
return o is Exception ex ? $"Huh, there was an Exception: {ex.Message}" : "Something went really wrong!";
|
|
});
|
|
}
|
|
|