You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/AI/Converters/StringToBoolConverter.cs

28 lines
749 B
C#

1 month ago
using Avalonia.Data.Converters;
using System;
using System.Globalization;
namespace AI.Converters
{
/// <summary>
/// 将字符串转换为布尔值(非空字符串为 true空或 null 为 false
/// </summary>
public class StringToBoolConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string str)
{
return !string.IsNullOrWhiteSpace(str);
}
return false;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}