Page view counter
How to GET the color of FILL Subscribe to this thread
Last post 10-23-2007 9:42 AM by kp2712. 6 replies.
Sort Posts:
09-19-2007 11:17 AM
How to GET the color of FILL

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 SndFill = Sender.Fill
var TmpRct = '<Rectangle Canvas.Left="100" Canvas.Top="100" Width="50" Height="50" Fill="'+SndFill+'" StrokeThickness="1" Stroke="blue"  />';

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

tom


TBink

Loading...
Joined on 05-01-2007
Posts 178
09-19-2007 11:22 AM
Re: How to GET the color of FILL

does fill.tostring() work?

=> Dave

Senior Engineer/Dev Manager, Vertigo Software
Vertigo

Dave Britton

Loading...
Joined on 06-27-2007
San Francisco Bay Area
Posts 229
09-19-2007 11:31 AM
Marked as Answer
Re: How to GET the color of FILL

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,

var SndFill = Sender.Fill.Color

var TmpRct = '<Rectangle Canvas.Left="'+(XPos-10)+'" Canvas.Top="'+(YPos-10)+'" Width="'+SWd+'" Height="'+SHt+'" Fill="red" StrokeThickness="1" Stroke="blue" Opacity="0.35" IsHitTestVisible="false"/>';

this.TempBlock = this.control.content.CreateFromXaml(TmpRct); this.TempBlock.Fill.Color = SndFill;

.... this works but it bothers me that I can't get a hex value for the color ....  seems to me to be a minor bug in the object model

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

 

TBink

Loading...
Joined on 05-01-2007
Posts 178
09-19-2007 8:49 PM
Marked as Answer
Re: How to GET the color of FILL

There is a thread on converting the color value you get here:
http://silverlight.net/forums/t/4710.aspx 


 

Jeff Paries

Loading...
Joined on 07-25-2007
Posts 106
10-05-2007 2:16 AM
Marked as Answer
Re: How to GET the color of FILL

 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;
}

(If this has answered your question, please click on "Mark as Answer")
Thanks & Rgds,
Suyog Kale
Senior Software Engineer
************************************************************

suyog kale

Loading...
Joined on 08-02-2007
pune-india
Posts 98
10-05-2007 12:50 PM
Re: How to GET the color of FILL

Many thanks... this is just what I was looking for!

TBink

Loading...
Joined on 05-01-2007
Posts 178
10-23-2007 9:42 AM
Re: How to GET the color of FILL

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?

kp2712

Loading...
Joined on 10-10-2007
Posts 7
Microsoft Communities