ControllerStateConverter.cs 1.09 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using FLY.Thick.Base.Common;
using System.Windows;

namespace FLY.Thick.Base.UI.Converter
{
    public class ControllerStateConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            CTRL_STATE state = (CTRL_STATE)value;
            var t= typeof(CTRL_STATE);
            string state_name = t.GetEnumName(state);

            string resourceName = $"str.ControllerState.{state_name}";
            string state_msg = (string)Application.Current.TryFindResource(resourceName);
            if (state_msg == null) 
            {
                state_msg = (string)Application.Current.TryFindResource("str.ControllerState.Unknown");
            }

            return state_msg;
        }

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