| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 | using System;using System.Collections.Generic;using System.Globalization;using System.Linq;using System.Text;using System.Windows.Data;using System.Windows.Media;using System.Windows;using Aitex.Core.RT.Log;namespace Aitex.Core.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 ControlWidthOrHeightConverter : IValueConverter    {        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            try            {                double tempValue = (double)value;                if (parameter == null)                {                    tempValue -= 30;                }                else                {                    double parValue = 0;                    double.TryParse((string)parameter, out parValue);                    tempValue -= parValue;                }                return tempValue;            }            catch (Exception ex)            {                LOG.Write(ex);            }            return value;        }        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 BoolToBoolReverseConverter : IValueConverter    {        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            try            {                if ((bool)value)                    return false;                return true;            }            catch (Exception ex)            {                LOG.Write(ex);            }            return true;        }        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            return null;        }    }    public class Bool2CollapsedReverseConverter : IValueConverter    {        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            try            {                if ((bool)value)                    return Visibility.Collapsed;                return Visibility.Visible;            }            catch (Exception ex)            {                LOG.Write(ex);            }            return Visibility.Visible;        }        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            return null;        }    }    public class Bool2HiddenReverseConverter : IValueConverter    {        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            try            {                if ((bool)value)                    return Visibility.Hidden;                return Visibility.Visible;            }            catch (Exception ex)            {                LOG.Write(ex);            }            return Visibility.Visible;        }        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            return null;        }    }    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 bool2VisibilityConverter2 : IValueConverter    {        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            try            {                if ((bool)value)                    return Visibility.Visible;                return Visibility.Collapsed;            }            catch (Exception ex)            {                LOG.Write(ex);            }            return Visibility.Collapsed;        }        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 BoolToValueConverter : IValueConverter    {        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)        {            if (value == null) return null;            return ((bool)value) ? parameter : DependencyProperty.UnsetValue;        }        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)        {            if (value == null) return null;            return object.Equals(value, parameter);        }    }    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;        }    }    public class FlowConverterForWeiQiMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == false)                    return isOpen;            }            return true;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    /// <summary>    /// 其中有一项为true就是true    /// </summary>    public class FlowConverterForAllTrueMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                    return isOpen;            }            return false;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    public class FlowConverterForAllTrueTurnGreenTwoMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                    return "#5BA05B";            }            return "#000000";        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    public class FlowConverterForAllTrueTurnGreenMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                    return Colors.Green;            }            return Colors.Gray;        }                  public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    public class FlowConverterForAllTrueTurnBlackToGreenMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                    return Colors.Green;            }            return Colors.Black;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    public class FlowConverterForAllFalseTurnGreenMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == false)                    return Colors.Gray;            }            return Colors.Green;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    public class FlowConverterForAllMoveSpeedMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            string str_Result = string.Empty;            bool isOpen = false;            double moveSpeed = 0;            for (int i = 0; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                {                    moveSpeed = 0.5;                    return moveSpeed;                }            }            return moveSpeed;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }    /// <summary>    /// 第一项false则关闭,后面的只要有true就打开    /// </summary>    public class FlowConverterFirstFalselMoveSpeedMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            double moveSpeed = 0;            if (values.Length < 2) return moveSpeed;            bool isOpen = false;            bool.TryParse(values.GetValue(0) + "", out isOpen);            if (!isOpen) return moveSpeed;            isOpen = false;            for (int i = 1; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                {                    moveSpeed = 0.5;                    return moveSpeed;                }            }            return moveSpeed;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }       /// <summary>    /// 第一项false则关闭,后面的只要有true就打开    /// </summary>    public class FlowConverterFirstFalseMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            if (values.Length < 2) return false;            bool isOpen = false;            bool.TryParse(values.GetValue(0) + "", out isOpen);            if (!isOpen) return false;                        isOpen = false;            for (int i = 1; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                    return true;            }            return false;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }        public class FlowConverterFirstFalseTurnGreenMultiBinding : IMultiValueConverter    {        #region IMultiValueConverter 成员        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)        {            if (values.Length < 2) return false;            bool isOpen = false;            bool.TryParse(values.GetValue(0) + "", out isOpen);            if (!isOpen) return Colors.Gray;                        isOpen = false;            for (int i = 1; i < values.Length; i++)            {                bool.TryParse(values.GetValue(i) + "", out isOpen);                if (isOpen == true)                    return Colors.Green;            }            return Colors.Gray;        }        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)        {            throw new NotImplementedException();        }        #endregion    }}
 |