using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Data; using System.Windows.Media; using System.Windows; using Aitex.Core.RT.Log; namespace Aitex.Smart.UI.Converters { public class LineColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { Color color = (Color)value; return new SolidColorBrush(color); } catch (Exception ex) { LOG.Write(ex); } return Brushes.Black; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { Brush brush = (SolidColorBrush)value; Color color = (Color)ColorConverter.ConvertFromString(brush.ToString()); return color; } catch (Exception ex) { LOG.Write(ex); } return Colors.Black; } } public class bool2VisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { if ((bool)value) return Visibility.Visible; return Visibility.Hidden; } catch (Exception ex) { LOG.Write(ex); } return Visibility.Hidden; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class Visibility2boolConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { Visibility vi = (Visibility)value; if (vi == Visibility.Visible) return true; return false; } catch (Exception ex) { LOG.Write(ex); } return true; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { bool isChecked = (bool)value; if (isChecked) return Visibility.Visible; return Visibility.Hidden; } catch (Exception ex) { LOG.Write(ex); } return Visibility.Visible; } } public class RolloverDataTimeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { DateTime dt; var isSucc = DateTime.TryParse(value.ToString(), out dt); if (isSucc) return string.Format("{0}{1}{2}", " 【", dt.ToString("yyyy/MM/dd HH:mm:ss"), "】 "); } return "N/A"; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class ColorToBrushConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { var color = (System.Windows.Media.Color)value; return new System.Windows.Media.SolidColorBrush(color); } catch (Exception ex) { LOG.Write(ex); } return System.Windows.Media.Brushes.Black; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class RolloverDataPointerInfoConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { DateTime time = (DateTime)values[0]; double y = (double)values[1]; return string.Format("【{0}】 {1}", time.ToString("yyyy/MM/dd HH:mm:ss"), y); } catch (Exception ex) { LOG.Write(ex); } return ""; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { return null; } } public class RadioBoolToIntConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { int integer = (int)value; if (integer == int.Parse(parameter.ToString())) return true; else return false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return parameter; } } }