Monday 25 April 2011

Convert string to Color object in SilverLight

Color c;
             Type colorType = (typeof(System.Windows.Media.Colors));
              if (colorType.GetProperty(slist.color) != null)
              {
                        object o = colorType.InvokeMember("Red", BindingFlags.GetProperty, null, null, null);
                        if (o != null)
                        {
                            c = (Color)o;
                        }
                        else
                        {
                            c = Colors.Black;
                        }
                    }
                    else
                    {
                        c = Colors.Black;
                    }
                    Brush color = new SolidColorBrush(c);  

No comments:

Post a Comment