Eric Dand
Eric Dand

Reputation: 1210

Get the hex code from the Foreground property of a TextBlock

There is plenty of documentation on how to set the Foreground property of a TextBlock element out there. I cannot, however, find any way to get the hex code as a string (e.g. "#FF000000" for black) from a TextBlock's Foreground property.

I'm working with Windows Phone 8/Silverlight.

Upvotes: 1

Views: 429

Answers (1)

Clemens
Clemens

Reputation: 128096

Provided that the Foreground property is set to a SolidColorBrush, you could just call

var colorString = ((SolidColorBrush)textBlock.Foreground).Color.ToString();

Upvotes: 4

Related Questions