Click here to Skip to main content
11,433,352 members (57,070 online)
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Silverlight: Use KnownColor Through the Backdoor

, 5 Aug 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
A possible alternative solution. I say possible because I have no idea if it will work in Silverlight and even if it does whether it will be any easier/faster. public Color ColorFromName(string name) { Color result = Colors.Black; Type type =...
A possible alternative solution. I say possible because I have no idea if it will work in Silverlight and even if it does whether it will be any easier/faster.

        public Color ColorFromName(string name)
        {
            Color result = Colors.Black;
            Type type = typeof(Brushes);
            foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Public | BindingFlags.Static))
            {
                if (propertyInfo.PropertyType == typeof(SolidColorBrush))
                {
                    if (propertyInfo.Name.ToLower() == name.ToLower())
                    {
                        result = ((SolidColorBrush)propertyInfo.GetValue(null, null)).Color;
                        break;
                    }
                }
            }
 
            return result;
        }

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Henry Minute
Retired
United Kingdom United Kingdom
Retired Systems Admin, Programmer, Dogsbody.
Mainly on Systems for Local Government, Health Authorities,
Insurance Industry - (COBOL eeeeeeeugh).
Inventor of Synchronized Shopping.

Comments and Discussions

 
GeneralWhoops missed the leading FF in Goldenrod Pin
Dean Wyant21-Sep-11 5:47
memberDean Wyant21-Sep-11 5:47 
GeneralThere are colors missing - looks like G through L. For insta... Pin
Dean Wyant21-Sep-11 5:41
memberDean Wyant21-Sep-11 5:41 
GeneralRe: Since my alternative doesn't contain a list of colours I can... Pin
Henry Minute21-Sep-11 6:26
memberHenry Minute21-Sep-11 6:26 
GeneralHey Henry, look at my 3rd edit. It's ultimately the best sol... Pin
John Simmons / outlaw programmer12-Aug-10 4:49
mvpJohn Simmons / outlaw programmer12-Aug-10 4:49 
GeneralMay be not. As eventually someone has to iterate through tha... Pin
Rama Krishna Vavilala5-Aug-10 15:46
memberRama Krishna Vavilala5-Aug-10 15:46 
GeneralLook at my 2nd edit. I think it will be faster than iteratin... Pin
John Simmons / outlaw programmer5-Aug-10 15:36
mvpJohn Simmons / outlaw programmer5-Aug-10 15:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150428.2 | Last Updated 5 Aug 2010
Article Copyright 2010 by Henry Minute
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid