123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using System;
- using System.Windows.Data;
- namespace VirgoUI.Client.Models.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();
- }
- }
- }
|