CtMicroGage.xaml.cs 2.74 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3
using FLY.OBJComponents.Client;
using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
4
using FLY.Thick.Base.IService;
潘栩锋's avatar
潘栩锋 committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
19
using Unity;
潘栩锋's avatar
潘栩锋 committed
20

潘栩锋's avatar
潘栩锋 committed
21
namespace FLY.Thick.Base.UI
潘栩锋's avatar
潘栩锋 committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
{
    /// <summary>
    /// UcMicroGage.xaml 的交互逻辑
    /// </summary>
    public partial class CtMicroGage : UserControl
    {
        CtMicroGageVm viewModel;
        /// <summary>
        /// 
        /// </summary>
        public CtMicroGage()
        {
            InitializeComponent();

            viewModel = new CtMicroGageVm();
            this.DataContext = viewModel;
        }
39

潘栩锋's avatar
潘栩锋 committed
40 41 42
        /// <summary>
        /// 初始化
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
43
        /// <param name="container">容器</param>
44
        [InjectionMethod]
潘栩锋's avatar
潘栩锋 committed
45
        public void Init(IUnityContainer container)
潘栩锋's avatar
潘栩锋 committed
46
        {
潘栩锋's avatar
潘栩锋 committed
47
            container.BuildUp(viewModel);
潘栩锋's avatar
潘栩锋 committed
48 49 50 51 52 53 54 55 56
        }
    }
    /// <summary>
    /// 
    /// </summary>
    public class IO2BitColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
57 58 59 60 61 62 63 64 65 66 67 68
            //ResourceDictionary resourceDictionary = new ResourceDictionary() { Source = new Uri("pack://application:,,,/FLY.Thick.Base.UI;component/CtMicroGage/CtMicroGageStyle.xaml") };
            //var onColor = resourceDictionary["Brushes.IO.ON"] as SolidColorBrush;
            //var offColor = resourceDictionary["Brushes.IO.OFF"] as SolidColorBrush;
            //if (onColor == null || offColor == null)
            //{
            //    onColor = new SolidColorBrush(Colors.WhiteSmoke);
            //    offColor = new SolidColorBrush(Colors.Black);
            //}
            var onColor = new SolidColorBrush(Colors.WhiteSmoke);
            var offColor = new SolidColorBrush(Color.FromArgb(0xFF, 0x3B, 0x3B, 0x3B));


潘栩锋's avatar
潘栩锋 committed
69 70 71 72 73 74
            try
            {
                UInt16 io = (UInt16)value;
                string str = (string)parameter;
                int bitno = int.Parse(str);
                if (Misc.MyBase.CHECKBIT(io, bitno))
75
                    return offColor;
潘栩锋's avatar
潘栩锋 committed
76
                else
77
                    return onColor;
潘栩锋's avatar
潘栩锋 committed
78 79 80
            }
            catch
            {
81
                return offColor;
潘栩锋's avatar
潘栩锋 committed
82 83 84 85 86 87 88 89 90 91
            }

        }

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