Skip to main content
Home Forums Silverlight Programming Programming with JavaScript How to GET the color of FILL
6 replies. Latest Post by kp2712 on October 23, 2007.
(0)
TBink
Member
254 points
188 Posts
09-19-2007 11:17 AM |
I want to GET the color of the FILL of a Rectangle.... the object xaml
<Rectangle X:Name="Test" Fill="#FFF85B5B" />
via script I want to get that color value and apply it to another object ... I can't find the way...
on mouse down I tried:
var
This fails and when I look at the text output for TmpRct I see Fill="SolidColorBrush"
Sender.Fill.Color gives a non hexidecimal, long number ... -500901
What's the solution...?
Dave Bri...
681 points
229 Posts
09-19-2007 11:22 AM |
does fill.tostring() work?
=> Dave
09-19-2007 11:31 AM |
Nope... In VisStudio I see
Sender.Fill.toString() "SolidColorBrush" String
I did do this work around since I simply want to apply the color of another object ... I can use the long value... so,
What I'd like to do is (bold italic):
var TmpRct = '<Rectangle Canvas.Left="'+(XPos-10)+'" Canvas.Top="'+(YPos-10)+'" Width="'+SWd+'" Height="'+SHt+'" Fill=="'+SndFill +'" StrokeThickness="1" Stroke="blue" Opacity="0.35" IsHitTestVisible="false"/>';
But this fails because its a long number
By the way there's the same issue with Stroke
Sender.Stroke.toString() "SolidColorBrush" String
tom
Jeff Paries
606 points
106 Posts
09-19-2007 8:49 PM |
There is a thread on converting the color value you get here:http://silverlight.net/forums/t/4710.aspx
suyog kale
188 points
98 Posts
10-05-2007 2:16 AM |
its simple
var vobj=document.getElementById("YourSilverlightObject"); var mainCanvas=vobj.content.findName("RectangleID"); var mainc=Convert.ToCanvas(mainCanvas); var sc=Convert.ToSolidColorBrush(mainc.get_background()); bgcolor=sc.get_color(); bgcolor=getFillColor(bgcolor);
//-------------------------------------------------------------------------------//-------Color value convertor function//-------Hexadecimal value from RGB Value//-------------------------------------------------------------------------------function getFillColor(color) { var fill = color; if (fill < 0) { fill = (16777216 + parseInt(fill)); } fill = fill.toString(16); if (fill.length > 6) { fill = fill.substr(fill.length - 6); } while (fill.length < 6) { fill = "0" + fill; } fill = "#ff" + fill; return fill;}
10-05-2007 12:50 PM |
Many thanks... this is just what I was looking for!
kp2712
8 points
7 Posts
10-23-2007 9:42 AM |
Hi,I want to do something similar..I want to obtain the background of a canvas(which is a LinearGradientBrush) and assign it to a rectagle's fill property.Can you tell me how to do it?