Convert Hex Color Code to Brush/SolidColorBrush in XAML App

To set the background color of an object in .NET XAML, you will need to set the Brush object type. To create a Brush object from a hexadecimal color code, use the following.

//input ex: #dcdcdc
public static Windows.UI.Xaml.Media.SolidColorBrush 
        GetColorFromHex(string hexaColor)
{
	return new Windows.UI.Xaml.Media.SolidColorBrush(
		Windows.UI.Color.FromArgb(
			255,
			Convert.ToByte(hexaColor.Substring(1, 2), 16),
			Convert.ToByte(hexaColor.Substring(3, 2), 16),
			Convert.ToByte(hexaColor.Substring(5, 2), 16)
		)
	);
}

Happy coding!

Advertsing

125X125_06

Planet Xamarin

Planet Xamarin

Calendar

<<  April 2018  >>
MonTueWedThuFriSatSun
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

View posts in large calendar

Month List