Files
WCS/Cowain.Base/Converters/StringToBoolConverter.cs
2026-03-02 09:08:20 +08:00

27 lines
666 B
C#

using Avalonia.Data.Converters;
using System.Globalization;
namespace Cowain.Base.Converters;
public class StringToBoolConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value != null && bool.TryParse(value.ToString(), out bool v))
{
return v;
}
return false;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value != null && value is bool boolValue)
{
return boolValue.ToString();
}
return string.Empty;
}
}