views:

29

answers:

1

While working with SilverLight using Visual Studio 10, I found that in design mode XAML allows a wide plethora of colors. For ex. Lime is a valid color in XAML.

<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
  <GradientStop Color="Yellow" Offset="0" />
  <GradientStop Color="Lime"  Offset="1" />

While working with code though, I found that Lime and many other colors are missing...

GradientStop blueGS = new GradientStop(); blueGS.Color = Colors.Lime;

What am I missing? Both of these colors belong to System.Windows.Media.Colors.

+1  A: 

From the MSDN page for System.Windows.Media.Colors (Silverlight version):

XAML Usage for Colors
You cannot instantiate objects from this managed class in XAML, but you can use its static properties to provide property values in XAML. There are additional named colors that can be specified in XAML, but these are not backed by static property values of Colors.

So, for whatever reason, it looks like you're effectively right; you can refer to more "named" colors in XAML than you can in the codebehind.

Also, you can always use the Color.FromArgb method in your code:

Color lime = Color.FromArgb(0xFF, 0x00, 0xFF, 0x00);
Donut
Thanks... But the main question still remains unanswered, why is it so?
Rahul Soni
Agreed; I hadn't noticed this before and now am wondering the same thing. MSDN states it quite matter-of-factly, but without any explanation as to why.
Donut