using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Windows; using System.Windows.Data; using System.Windows.Media; namespace FLY.Weight2.UI.Client { public class WeighterColorDB { class WeighterColor { public Brush Self; public WeighterColor() { } } static List mWeighters; static WeighterColorDB() { //if (File.Exists("weighterColorDb.json")) //{ // string json = File.ReadAllText("weighterColorDb.json"); // mWeighters = Newtonsoft.Json.JsonConvert.DeserializeObject>(json); //} //else //{ ResourceDictionary r = new ResourceDictionary() { Source = new Uri("pack://application:,,,/FLY.Weight2.UI.Client;component/Themes/Dictionary_CellColor.xaml") }; mWeighters = new List(); for (int i = 0; i < 5; i++) { WeighterColor c = new WeighterColor(); string color_name = "Color_g" + (i + 1).ToString() + "#0"; c.Self = r[color_name] as Brush; mWeighters.Add(c); } //} } public static Brush GetSelf(int index) { if (index<0 || index>=mWeighters.Count()) return null; return mWeighters[index].Self; } } public class Number2ColorValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { int index = (int)value; return WeighterColorDB.GetSelf(index); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }