wip
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace Toolkit.UI.WinUI;
|
||||
|
||||
public class IsStringNotNullOrEmptyConverter :
|
||||
ValueConverter<string, bool>
|
||||
{
|
||||
protected override bool ConvertTo(string value, Type? targetType, object? parameter, string? language) =>
|
||||
!string.IsNullOrEmpty(value);
|
||||
}
|
||||
@@ -4,24 +4,17 @@ using System.Globalization;
|
||||
namespace Toolkit.UI.WinUI;
|
||||
|
||||
public class StringFormatConverter :
|
||||
ValueConverter<object, object>
|
||||
ValueConverter<object?, object?>
|
||||
{
|
||||
public string? StringFormat { get; set; }
|
||||
|
||||
protected override object? ConvertTo(object value,
|
||||
protected override object? ConvertTo(object? value,
|
||||
Type? targetType,
|
||||
object? parameter,
|
||||
string? language)
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
return null!;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(StringFormat))
|
||||
{
|
||||
return value.ToString()!;
|
||||
}
|
||||
if (value is null) return null!;
|
||||
if (StringFormat is not { Length: > 0}) return $"{value}"!;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Toolkit.UI.WinUI;
|
||||
|
||||
public class ValidationBooleanConverter :
|
||||
ValueConverter<IReadOnlyIndexDictionary<string, string>, bool>
|
||||
{
|
||||
public string? Property { get; set; }
|
||||
|
||||
public bool TrueValue { get; set; } = true;
|
||||
|
||||
public bool FalseValue { get; set; } = false;
|
||||
|
||||
protected override bool ConvertTo(IReadOnlyIndexDictionary<string, string> value,
|
||||
Type? targetType,
|
||||
object? parameter,
|
||||
string? language)
|
||||
{
|
||||
if (Property is { Length: > 0 } && value.ContainsKey(Property))
|
||||
{
|
||||
return TrueValue;
|
||||
}
|
||||
|
||||
return FalseValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using Toolkit.Foundation;
|
||||
|
||||
namespace Toolkit.UI.WinUI;
|
||||
|
||||
public class ValidationMessageConverter :
|
||||
ValueConverter<IReadOnlyIndexDictionary<string, string>, string?>
|
||||
{
|
||||
public string? Property { get; set; }
|
||||
|
||||
protected override string? ConvertTo(IReadOnlyIndexDictionary<string, string> value,
|
||||
Type? targetType,
|
||||
object? parameter,
|
||||
string? language)
|
||||
{
|
||||
if (Property is { Length: > 0 } && value.TryGetValue(Property, out string? message))
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user