Commit 12108025 by liulongfei

添加多值转化器

parent 22a4fb1a
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// 多Bool转化器
/// </summary>
public class MultiBool2BoolConverter : IMultiValueConverter
{
/// <summary>
/// 掩码True
/// </summary>
public const string MASK_TRUE = "1";
/// <summary>
/// 掩码False
/// </summary>
public const string MASK_FALSE = "0";
/// <summary>
/// 掩码
/// </summary>
/// <remarks>
/// 1 : true
/// 0 : false
/// 逗号或空格分割
/// 例如: 1,0,1
/// </remarks>
public string Mask { get; set; }
/// <summary>
/// 匹配返回
/// </summary>
public bool MatchResult { get; set; } = true;
/// <summary>
/// 未匹配返回
/// </summary>
public bool NotMatchResult { get; set; } = false;
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null)
return this.NotMatchResult;
string[] mask = this.Mask.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (values.Length != mask.Length)
return this.NotMatchResult;
for (int i = 0; i < mask.Length; i++)
{
bool? b = values[i] as bool?;
bool real = b == null ? false : b.Value;
string m = mask[i];
if ((real && m == MASK_TRUE) || (!real && m == MASK_FALSE))
continue;
return this.NotMatchResult;
}
return this.MatchResult;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
...@@ -103,6 +103,7 @@ ...@@ -103,6 +103,7 @@
<Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" /> <Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" />
<Compile Include="Core\Converter\Color2SolidColorBrushConverter.cs" /> <Compile Include="Core\Converter\Color2SolidColorBrushConverter.cs" />
<Compile Include="Core\Converter\Enum2EnumDescriptionConverter.cs" /> <Compile Include="Core\Converter\Enum2EnumDescriptionConverter.cs" />
<Compile Include="Core\Converter\MultiBool2BoolConverter.cs" />
<Compile Include="Core\Converter\ObjectNotNull2BoolConverter.cs" /> <Compile Include="Core\Converter\ObjectNotNull2BoolConverter.cs" />
<Compile Include="Core\Converter\String2ImageSourceConverter.cs" /> <Compile Include="Core\Converter\String2ImageSourceConverter.cs" />
<Compile Include="Core\Converter\StringAppendConverter.cs" /> <Compile Include="Core\Converter\StringAppendConverter.cs" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment