I’ve been asked by a client if it was possible to make color versions of a design. I told him that that was actually very easy. And it is. It is just that you have to treat your colors a little different: you’ll have to create color palettes using Color Resources. Because that worked a little different in Silverlight 2 Beta 1 than in WPF I was on the wrong foot for a long time. Finally I worked it out and here it is:
There’s only one way to specify a Color in Silverlight:
[sourcecode language=”XML”]
and this gets underlined in Visual Studio indicating that Color cannot have direct content (meaning the color code between the <Color> and </Color> tags). You’ll have to ignore that 🙂
All other ways to specify color won’t work in Silverlight:
[sourcecode language=”XML”]
[/sourcecode]
Note that at least the second and the fourth are valid in WPF. The third seems to go well in Blend, but gives an error in the browser and won’t show anything: the screen remains white.
Still, this allows you to create palettes of color. Here’s one with two colors:
[sourcecode language=”XML”]
[sourcecode language=”XML”]
You can use these in SolidColorBrushes and LinearGradienBrushes like these:
[sourcecode language=”XML”]
[/sourcecode]
Place all this in app.xaml between de <Application.Resources> tags and you’ll be ready to apply them in some normal XAML:
[sourcecode language=”XML”]
[/sourcecode]
What makes it easy to make color versions of a design is the fact that you can easily replace the two color codes in the Palette to change the look of the entire application! This would do the trick:
[sourcecode language=”XML”]
[/sourcecode]
Be aware of the use of a Color Resource (colBright) in a LinearGradientBrush, but a Brush Resource (brBright) when you use it for a Fill or a Stroke.
So with about 10 colors as resource in app.xaml, you can actually create a basis for skinning your application. It’s just that now I still have to replace all the separated colors in my project with StaticResources and that will take some time… So now it is easy, but it will take a while 🙂 If you remember to work like this from scratch, you’ll be fine when a client ask you if color versions are possible…
Njoy!