IO2BitVisableConverter.cs 1.81 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

using System.Windows.Media;

潘栩锋's avatar
潘栩锋 committed
9
namespace FLY.Thick.Base.UI.Converter
潘栩锋's avatar
潘栩锋 committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
{
    public class IO2BitColorConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            SolidColorBrush Color_theme_activity = new SolidColorBrush(Color.FromArgb(0xFF, 0x00, 0x8B, 0xE5));
            SolidColorBrush Color_theme_static = new SolidColorBrush(Color.FromArgb(0xFF, 0x3B, 0x3B, 0x3B));
            try
            {
                UInt16 io = (UInt16)value;
                string str = (string)parameter;
                int bitno = int.Parse(str);
                if (Misc.MyBase.CHECKBIT(io, bitno))
                    return Color_theme_static;
                else
                    return Color_theme_activity;
            }
            catch{
                    return Color_theme_static;
            }
            
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    public class IO2BinConverter : IValueConverter
    {
        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            UInt16 io = (UInt16)value;
            string str = System.Convert.ToString(io, 2);

            return str.PadLeft(10, '0');
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}