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/FormBoolConverter.cs

33 lines
891 B
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Globalization;
using Avalonia.Data.Converters;
namespace AI.Converters
{
/// <summary>
/// 表单布尔字段与字符串双向转换CheckBox 与 CurrentValue 绑定)
/// </summary>
public class FormBoolConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string s)
{
var v = s?.Trim() ?? string.Empty;
return v is "1" or "true" or "True" or "yes" or "是";
}
return false;
}
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool b)
{
return b ? "True" : "False";
}
return "False";
}
}
}