private static object GetValue(string key, string converter)
        {
#if DEBUG
            if (Application.Current.MainWindow == null)
            {
                return(null);                                                    // designmode
            }
#endif

            var obj = ThemeManager.Inst.CurrentTheme.Get(key);

            if (string.IsNullOrWhiteSpace(converter))
            {
                if (obj is ColorRef cref)
                {
                    return(ColorRefToBrush.Convert(cref));
                }
                if (obj is BrushRef bref)
                {
                    return(BrushRefToBrush.Convert(bref));
                }
                if (obj is ThicknessRef tref)
                {
                    return(tref.ToWThickness());
                }
                if (obj is CornerRadiusRef rref)
                {
                    return(rref.ToCornerRad());
                }

                throw new Exception($"Cannot convert {obj?.GetType()} to 'brush'");
            }
            else if (converter.Equals("ToColor", StringComparison.InvariantCultureIgnoreCase))
            {
                if (obj is ColorRef cref)
                {
                    return(cref.ToWCol());
                }
                if (obj is BrushRef bref)
                {
                    return(bref.GradientSteps.First().Item2.ToWCol());
                }

                throw new Exception($"Cannot convert {obj?.GetType()} with '{converter}'");
            }
            else
            {
                throw new Exception($"Unknown converter {converter}");
            }
        }
Exemplo n.º 2
0
        private static object GetValue(string key, string converter, string rtype)
        {
#if DEBUG
            if (Application.Current.MainWindow == null)
            {
                return(null);                                                    // designmode
            }
#endif

            if (rtype == "Value")
            {
                var obj = ThemeManager.Inst.CurrentThemeSet.Get(key);

                if (string.IsNullOrWhiteSpace(converter))
                {
                    if (obj is ColorRef cref)
                    {
                        return(ColorRefToBrush.Convert(cref));
                    }
                    if (obj is BrushRef bref)
                    {
                        return(BrushRefToBrush.Convert(bref));
                    }
                    if (obj is ThicknessRef tref)
                    {
                        return(tref.ToWThickness());
                    }
                    if (obj is CornerRadiusRef rref)
                    {
                        return(rref.ToCornerRad());
                    }

                    throw new Exception($"Cannot convert {obj?.GetType()} to 'brush'");
                }
                else if (converter.Equals("ToColor", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (obj is ColorRef cref)
                    {
                        return(cref.ToWCol());
                    }
                    if (obj is BrushRef bref)
                    {
                        return(bref.GradientSteps.First().Item2.ToWCol());
                    }

                    throw new Exception($"Cannot convert {obj?.GetType()} with '{converter}'");
                }
                else if (converter.Equals("ToScrollBarVisibility", StringComparison.InvariantCultureIgnoreCase))
                {
                    var boolobj = (bool)obj;
                    return(boolobj ? ScrollBarVisibility.Auto : ScrollBarVisibility.Hidden);
                }
                else
                {
                    throw new Exception($"Unknown converter '{converter}'");
                }
            }
            else if (rtype == "ImageSource")
            {
                return(ThemeManager.Inst.CurrentThemeSet.GetBitmapImageResource(key));
            }
            else
            {
                throw new Exception($"Unknown ResType '{rtype}'");
            }
        }
Exemplo n.º 3
0
 public static System.Windows.Media.Brush ToWBrush(this BrushRef cref)
 {
     return(BrushRefToBrush.Convert(cref));
 }