Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Silverlight: Use KnownColor Through the Backdoor

, 5 Aug 2010
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 PinmemberDean Wyant21-Sep-11 4:47 
GeneralThere are colors missing - looks like G through L. For insta... PinmemberDean Wyant21-Sep-11 4:41 
GeneralRe: Since my alternative doesn't contain a list of colours I can... PinmemberHenry Minute21-Sep-11 5:26 
GeneralHey Henry, look at my 3rd edit. It's ultimately the best sol... PinmvpJohn Simmons / outlaw programmer12-Aug-10 3:49 
GeneralMay be not. As eventually someone has to iterate through tha... PinmemberRama Krishna Vavilala5-Aug-10 14:46 
GeneralLook at my 2nd edit. I think it will be faster than iteratin... PinmvpJohn Simmons / outlaw programmer5-Aug-10 14: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 | Mobile
Web03 | 2.8.140814.1 | Last Updated 5 Aug 2010
Article Copyright 2010 by Henry Minute
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid