27 lines
666 B
C#
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;
|
|
}
|
|
}
|