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

前端 未结 8 1699
执念已碎
执念已碎 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:06

    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.

    // Get a Color instance representing #FFFF0000.
    var color = XamlBindingHelper.ConvertValue(typeof(Windows.UI.Color), "red");
    

    It can convert enums from Windows.UI.Xaml namespace, booleans, brushes, colors and other simple stuff XAML parser is able to do.

提交回复
热议问题