Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Canvas Color
3 replies. Latest Post by ccoombs on October 29, 2008.
(0)
vicraze
Member
70 points
111 Posts
10-29-2008 11:49 AM |
hi
I want to change my canvas color dynamically so im writing like this
Canvas.Background =
but i dont want Red color or any other built in colors ...i want to use my own color like #FF0000 ,#F2F2F2
how can use like this??????any idea
thanks in advance
vijay
ccoombs
Contributor
5122 points
755 Posts
10-29-2008 11:53 AM |
Color.FromArgb will give you what you need. just provide alpha, red, green, blue values.
#FF0000 = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0))
#F2F2F2 = new SolidColorBrush(Color.FromArgb(255, 242, 242, 242))
10-29-2008 12:01 PM |
hi thanks for your quick reply
i have a problm here....
i dont know what color im goin to get, it comes from my xml as a string.....so im unable to use Color.FromArgb...
any suggestion pls..
thanks
10-29-2008 12:27 PM |
you just need to convert from your hex string to the appropriate byte values. create a helper function if you want...
private Color hexToColor(string hexString) { hexString = hexString.Replace("#", ""); Byte a = 255; Byte r = Convert.ToByte(hexString.Substring(0, 2), 16); Byte g = Convert.ToByte(hexString.Substring(2, 2), 16); Byte b = Convert.ToByte(hexString.Substring(4, 2), 16); return Color.FromArgb(a, r, g, b); }