Converting a string HEX to color in Windows Phone Runtime c#

前端 未结 8 1672
执念已碎
执念已碎 2021-02-09 07:30

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 so

8条回答
  •  甜味超标
    2021-02-09 08:19

    generete a file namely: ColorUtils.cs

    using Windows.UI.Xaml.Markup;
    ....
     static class ColorUtils
        {
            public static Color GetColorFromHex(string hexString)
            {
                Color x =(Color)XamlBindingHelper.ConvertValue(typeof(Color), hexString);
                return x;
            }
        }
    

    and use it something like

    var acolor=(new SolidColorBrush(ColorUtils.GetColorFromHex("#F24C27")):
    

    or with alpha

    var acolor=(new SolidColorBrush(ColorUtils.GetColorFromHex("#4CF24C27")):
    

提交回复
热议问题