Commit ea567a1c by liulongfei

添加转化器

parent 8c821add
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// Bool转控件模板转化器
/// </summary>
public class Bool2ControlTemplateConverter : IValueConverter
{
/// <summary>
/// 为False时的值
/// </summary>
public ControlTemplate FalseResult { get; set; }
/// <summary>
/// 为True时的值
/// </summary>
public ControlTemplate TrueResult { get; set; }
/// <summary>
/// 为null时的值
/// </summary>
public ControlTemplate NullResult { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool?)
{
bool? b = (bool?)value;
if (b == null)
return this.NullResult;
return b.Value ? this.TrueResult : this.FalseResult;
}
else if (value is bool)
{
bool b = (bool)value;
return b ? this.TrueResult : this.FalseResult;
}
else
{
return this.NullResult;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace VIZ.Framework.Core
{
/// <summary>
/// Bool转数据模板转化器
/// </summary>
public class Bool2DataTemplateConverter : IValueConverter
{
/// <summary>
/// 为False时的值
/// </summary>
public DataTemplate FalseResult { get; set; }
/// <summary>
/// 为True时的值
/// </summary>
public DataTemplate TrueResult { get; set; }
/// <summary>
/// 为null时的值
/// </summary>
public DataTemplate NullResult { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool?)
{
bool? b = (bool?)value;
if (b == null)
return this.NullResult;
return b.Value ? this.TrueResult : this.FalseResult;
}
else if (value is bool)
{
bool b = (bool)value;
return b ? this.TrueResult : this.FalseResult;
}
else
{
return this.NullResult;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
......@@ -93,6 +93,8 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Core\Converter\Bool2ControlTemplateConverter.cs" />
<Compile Include="Core\Converter\Bool2DataTemplateConverter.cs" />
<Compile Include="Core\Converter\Bool2ImageSourceConverter.cs" />
<Compile Include="Core\Converter\Bool2BoolConverterSimple.cs" />
<Compile Include="Core\Converter\Bool2BoolConverter.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