Tuesday, May 4, 2010

Sivlerlight Colors Lack of ColorTranslator

System.Windows.Media used for colors by Silverlight  does not have ColorTranslator which would be convenient to specify a color using ColorTranslator.FromHtml(“AliceBlue”).

Colors like AliceBlue is  available in XAML but not in code behind where you have to use Color.FromArgb Method or the following code mentioned in Color Structure

String xamlString = "<Canvas xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" Background=\"MistyRose\"/>";



Canvas c = (Canvas) System.Windows.Markup.XamlReader.Load(xamlString);



SolidColorBrush mistyRoseBrush = (SolidColorBrush) c.Background;



Color mistyRose = mistyRoseBrush.Color;




Laurent Duveau has an interesting solution to this problem in this blog Silverlight – Get Color from Hex



where he shows how to get ColorTranslator with Hex values!

No comments:

Post a Comment