53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Data;
|
|
using System.Windows.Media;
|
|
|
|
using Wpf.Ui.Controls;
|
|
|
|
namespace Wpf.Ui.Extend.Converters;
|
|
public class StringToColorConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value.ToString();
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
string str = value.ToString();
|
|
Regex regex = new Regex("^#(?:[0-9a-fA-F]{3}){1,2}$");
|
|
if (regex.IsMatch(str))
|
|
{
|
|
var color = ColorConverter.ConvertFromString(str);
|
|
return color;
|
|
}
|
|
|
|
return Binding.DoNothing;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 判断值是否为空
|
|
/// </summary>
|
|
public class StringIsEmptyConverter : IValueConverter
|
|
{
|
|
#region IValueConverter 成员
|
|
|
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
return string.IsNullOrEmpty(System.Convert.ToString(value));
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#endregion
|
|
}
|