如何在Windows 8中将十六进制代码转换为颜色

Pra*_*ran 0 windows-runtime

我有代码十六进制代码"FFB800",我需要在WinRT中转换为"颜色".

提前致谢.

Hut*_*wer 5

问题的目的是什么?是否可以在普通的XAML中执行此操作?XAML确实采用十六进制代码.

    <Grid Background="#FFB800">
Run Code Online (Sandbox Code Playgroud)

否则在代码隐藏中我在Windows 8应用程序中使用了或多或少的以下内容:

    var hexCode = "#FFFFB800";
    var color = new Color();
    color.A = byte.Parse(hexCode.Substring(1, 2), NumberStyles.AllowHexSpecifier);
    color.R = byte.Parse(hexCode.Substring(3, 2), NumberStyles.AllowHexSpecifier);
    color.G = byte.Parse(hexCode.Substring(5, 2), NumberStyles.AllowHexSpecifier);
    color.B = byte.Parse(hexCode.Substring(7, 2), NumberStyles.AllowHexSpecifier);
Run Code Online (Sandbox Code Playgroud)