Skip to main content

Microsoft Silverlight

Answered Question Change colorsRSS Feed

(0)

Galaad
Galaad

Member

Member

152 points

75 Posts

Change colors

 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 :)

You're welcome to Aerilys at www.aerilys.fr. Tutorials and games.
Soon, Solaris Project, multiplayers game in Silverlight at www.solaris.aerilys.fr.

Qbus
Qbus

Member

Member

607 points

269 Posts

Re: Change colors

 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.

 

--------------------------
Please mark the post as answered if this answers your question
http://www.laumania.net

Galaad
Galaad

Member

Member

152 points

75 Posts

Re: Change colors

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...

You're welcome to Aerilys at www.aerilys.fr. Tutorials and games.
Soon, Solaris Project, multiplayers game in Silverlight at www.solaris.aerilys.fr.

ben33333
ben33333

Member

Member

50 points

11 Posts

Answered Question

Re: Change colors

 I think for code it would be:

 Rectangle.Fill = new SolidColorBrush(Colors.Red);

 

-Ben

Galaad
Galaad

Member

Member

152 points

75 Posts

Re: Change colors

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 :)

You're welcome to Aerilys at www.aerilys.fr. Tutorials and games.
Soon, Solaris Project, multiplayers game in Silverlight at www.solaris.aerilys.fr.

Qbus
Qbus

Member

Member

607 points

269 Posts

Answered Question

Re: Change colors

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 :)

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?

new SolidColorBrush(Color.FromArgb(0, 0, 139, 139))

should be

new SolidColorBrush(Color.FromArgb(255, 0, 139, 139))

--------------------------
Please mark the post as answered if this answers your question
http://www.laumania.net

Galaad
Galaad

Member

Member

152 points

75 Posts

Re: Change colors

 In fact,

new SolidColorBrush(Color.FromArgb(0, 0, 139, 139)) 

 

is good, but not correspond to DarkCyan, but your code is operative ! So thank you :D

You're welcome to Aerilys at www.aerilys.fr. Tutorials and games.
Soon, Solaris Project, multiplayers game in Silverlight at www.solaris.aerilys.fr.

drnomad
drnomad

Member

Member

206 points

58 Posts

Re: Re: Change colors

I find the "AllColorsHelper" class on this page very useful:

 http://www.onedotnetway.com/silverlight-predefined-colors-what-color-are-they/

 

Online Silverlight games on http://www.seujogo.com

drnomad
drnomad

Member

Member

206 points

58 Posts

Re: Change colors

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

 

Online Silverlight games on http://www.seujogo.com
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities