101 lines
2.9 KiB
C#
101 lines
2.9 KiB
C#
|
using System;
|
|||
|
using System.Windows.Data;
|
|||
|
|
|||
|
namespace MECF.Framework.UI.Client.Ctrlib.Converter
|
|||
|
{
|
|||
|
public class Bit2Bool : IValueConverter
|
|||
|
{
|
|||
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
if (!(value is int))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
int tempValue = (int)value;
|
|||
|
return tempValue == 1;
|
|||
|
}
|
|||
|
|
|||
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
if (!(value is bool))
|
|||
|
{
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
bool tempValue = (bool)value;
|
|||
|
return tempValue == true ? 1 : 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class Null2Bool : IValueConverter
|
|||
|
{
|
|||
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
return value == null;
|
|||
|
}
|
|||
|
|
|||
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class String2Double : IValueConverter
|
|||
|
{
|
|||
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
if (value == null)
|
|||
|
return 0.0;
|
|||
|
|
|||
|
double tempValue = 0.0;
|
|||
|
double.TryParse(value.ToString(), out tempValue);
|
|||
|
|
|||
|
return tempValue;
|
|||
|
}
|
|||
|
|
|||
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class Bool2Not : IValueConverter
|
|||
|
{
|
|||
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
if (!(value is bool))
|
|||
|
return false;
|
|||
|
|
|||
|
return !(bool)value;
|
|||
|
}
|
|||
|
|
|||
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
if (!(value is bool))
|
|||
|
return false;
|
|||
|
|
|||
|
return !(bool)value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class Float2String : IValueConverter
|
|||
|
{
|
|||
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
if (value == null)
|
|||
|
return string.Empty;
|
|||
|
|
|||
|
if (double.IsNaN((double)value))
|
|||
|
return string.Empty;
|
|||
|
else
|
|||
|
return value;
|
|||
|
}
|
|||
|
|
|||
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|