I am working on a windows phone game, and I got stuck when I wanted to convert a HEX string into Color. On windows phone 8 silverlight it is not a problem but I cannot find a solution in runtime because it doesn't include Color.FromArgb, or Color.FromName functions.
Does somebody have a function that converts string HEX to Color?
Thanks.
Final solution, that works as well on UWP:
generete a file namely: ColorUtils.cs
and use it something like
or with alpha
I made a method from the top answer here:
You can use
Converting Hex to Color in C# for Universal Windows Platform (UWP)
Create a method to Convert Hex string to SolidColorBrush:
Now all that left is to get the color by Calling the method and pass the hex string to it as parameter:
Reference: http://www.joeljoseph.net/converting-hex-to-color-in-universal-windows-platform-uwp/
Just in case someone is looking for a better alternative. In Universal Windows Platform (Windows 10), there is
XamlBindingHelper.ConvertValue
, which is much better than nothing.It can convert enums from Windows.UI.Xaml namespace, booleans, brushes, colors and other simple stuff XAML parser is able to do.