using FLY.OBJComponents.Client;
using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
using FLY.Thick.Base.IService;
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;
using Unity;

namespace FLY.Thick.Base.UI
{
    /// <summary>
    /// UcMicroGage.xaml 的交互逻辑
    /// </summary>
    public partial class CtMicroGage : UserControl
    {
        CtMicroGageVm viewModel;
        /// <summary>
        /// 
        /// </summary>
        public CtMicroGage()
        {
            InitializeComponent();

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

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="container">容器</param>
        [InjectionMethod]
        public void Init(IUnityContainer container)
        {
            container.BuildUp(viewModel);
        }
    }
    /// <summary>
    /// 
    /// </summary>
    public class IO2BitColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //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));


            try
            {
                UInt16 io = (UInt16)value;
                string str = (string)parameter;
                int bitno = int.Parse(str);
                if (Misc.MyBase.CHECKBIT(io, bitno))
                    return offColor;
                else
                    return onColor;
            }
            catch
            {
                return offColor;
            }

        }

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