Skip to main content
Home Forums Silverlight Programming Game Development Change colors
8 replies. Latest Post by drnomad on July 9, 2009.
(0)
Galaad
Member
152 points
75 Posts
07-06-2009 3:12 PM |
Hello Everybody !
For one of my game, I want to give to player, the choice of change the color of the interface. I know how modify the color of text for example, but I've not find in documentation or internet, how change the color (the "Fill") of a rectangle. If someone knows the answer...
Thank You :)
Qbus
607 points
269 Posts
07-06-2009 3:24 PM |
Well, it depends on the element as I recall it. But for rectagle its:
<Rectangle Fill="#FFAABBCC"></Rectangle>
And in code it would be:Rectagle.Fill = Color.Red;
If you need an "Color" object from a HEX in code, I have made a little helper method for that: http://laumania.net/post/From-HEX-%28string%29-to-Color-in-Silverlight.aspx
Hope it helps.
07-06-2009 3:49 PM |
It doesn't work, because with Rectangle.Fill, we cannot write Color.Red. It works with a Colors.Red. But, unhappily, I want DarkCyan color, and this is not exists with Colors. I've test too with a Color.FromArgb(0, 0, 139, 139), but it's not compatible.
In the worse case, I can use a linearGradientBrush like that :
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1"> <GradientStop x:Name="gradient_rect_G" Color="DarkCyan" Offset="0.8"/> <GradientStop Color="LightGray" Offset="0.95"/> <GradientStop Color="Black" Offset="0.65"/> </LinearGradientBrush>
and
gradient_rect.Color = Color.FromArgb(0, 0, 139, 139);
but I think it's not the best solution...
ben33333
50 points
11 Posts
I think for code it would be:
Rectangle.Fill = new SolidColorBrush(Colors.Red);
-Ben
07-06-2009 3:56 PM |
it's okay with a
new SolidColorBrush(Color.FromArgb(0, 0, 139, 139))
for the DarkCyan (just the color code which is not good ).
Thank You all :)
07-08-2009 5:27 AM |
Galaad: it's okay with a new SolidColorBrush(Color.FromArgb(0, 0, 139, 139)) for the DarkCyan (just the color code which is not good ). Thank You all :)
it's okay with a new SolidColorBrush(Color.FromArgb(0, 0, 139, 139)) for the DarkCyan (just the color code which is not good ).
Yeah sorry for my earlier post, ofcause it's Colors.Red, not Color.Red. And ofcause it's a Brush, not jsut a color, sorry again :) But your problem here, you say the color isn't right. That might be because you set the alpha channel to 0?
should be
new SolidColorBrush(Color.FromArgb(255, 0, 139, 139))
07-08-2009 1:49 PM |
In fact,
is good, but not correspond to DarkCyan, but your code is operative ! So thank you :D
drnomad
206 points
58 Posts
07-09-2009 2:24 AM |
I find the "AllColorsHelper" class on this page very useful:
http://www.onedotnetway.com/silverlight-predefined-colors-what-color-are-they/
07-09-2009 10:13 AM |
After rechecking previous link, it differs from what I had in mind. Read the following, which is easier in code:
http://silverlight.net/forums/p/13225/43867.aspx