StringLengthToBoolConverter.cs
900 Bytes
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace HHECS.WinCommon.ValueConverter
{
/// <summary>
/// 字符串长度转换为bool
/// 长度大于0转换为true,否则为false
/// </summary>
public class StringLengthToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string result)
{
return result.Length > 0;
}
else
{
return false;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}