You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.3 KiB
66 lines
2.3 KiB
2 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Globalization;
|
||
|
using System.Linq;
|
||
|
using System.Text;
|
||
|
using System.Windows.Data;
|
||
|
|
||
|
namespace BBWY.Client.Converters
|
||
|
{
|
||
|
public class TaskStateToBooleanConvert : IValueConverter
|
||
|
{
|
||
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||
|
{
|
||
|
string[] parray = parameter.ToString().ToLower().Split(':');//参数拆分
|
||
|
string valueStr = value == null ? string.Empty : value.ToString().ToLower();
|
||
|
string returnValue = string.Empty;
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(valueStr))
|
||
|
{
|
||
|
returnValue = parray[0].Contains("#null") ? parray[1] : parray[2];
|
||
|
}
|
||
|
else if (parray[0].Contains("|"))
|
||
|
{
|
||
|
returnValue = parray[0].Split('|').Contains(valueStr) ? parray[1] : parray[2];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
returnValue = parray[0].Equals(valueStr) ? parray[1] : parray[2];
|
||
|
}
|
||
|
if (returnValue.Equals("#source", StringComparison.CurrentCultureIgnoreCase))
|
||
|
return value;
|
||
|
return returnValue;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||
|
Console.WriteLine($"ObjectConverter {ex.Message} {parameter}");
|
||
|
Console.ResetColor();
|
||
|
}
|
||
|
return parray[2];
|
||
|
}
|
||
|
|
||
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||
|
{
|
||
|
var returnValue = "otherValue";
|
||
|
string[] parray = parameter.ToString().ToLower().Split(':');
|
||
|
if (value == null)
|
||
|
return returnValue;
|
||
|
var valueStr = value.ToString().ToLower();
|
||
|
if (valueStr != parray[1])
|
||
|
return returnValue;
|
||
|
else
|
||
|
{
|
||
|
var resData = parray[0].Contains('|') ? parray[0].Split('|')[0] : parray[0];
|
||
|
if (resData == "#null")
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
return resData;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
}
|