使用Xamarin在XAML中指定RGB颜色 [英] Specify a RGB color in XAML with Xamarin

查看:225
本文介绍了使用Xamarin在XAML中指定RGB颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中创建一些应用程序样式,并希望定义一些显式的颜色以供键使用.在WPF XAML中,我将创建一个SolidColorBrush来定义RGB/ARGB值.在Xamarin XAML中,是否需要将其转换为十六进制以在XAML中定义相同的颜色?下面的代码段来自WPF XAML.

I'm creating some application styles in my app and want to define some explicit colors to use by key. In WPF XAML, I would create a SolidColorBrush to define the RGB/ARGB values. In Xamarin XAML, do I need to convert this to hex to define the same color in XAML? The snippet below is from WPF XAML.

<SolidColorBrush
    x:Key="blueColor">
    <SolidColorBrush.Color>
        <Color
            A="255"
            R="50"
            G="150"
            B="225" />
    </SolidColorBrush.Color>
</SolidColorBrush>

推荐答案

Xamarin.Forms提供了一个跨平台的Color类.

Xamarin.Forms provides a cross-platform Color class.

使用Xaml:

Using from Xaml:

还可以使用定义的颜色名称或此处显示的十六进制表示形式在Xaml中轻松引用颜色:

<Label Text="Sea color" BackgroundColor="Aqua" />
<Label Text="RGB" BackgroundColor="#00FF00" />
<Label Text="Alpha plus RGB" BackgroundColor="#CC00FF00" />
<Label Text="Tiny RGB" BackgroundColor="#0F0" />
<Label Text="Tiny Alpha plus RGB" BackgroundColor="#C0F0" />

Color类提供了许多构建颜色实例的方法

The Color class provides a number of methods to build a color instance

  • 命名颜色-常见的命名颜色的集合,包括Red,Green和Blue.
  • FromHex-类似于HTML中使用的语法的字符串值,例如"00FF00".
  • 可以选择将Alpha指定为第一对字符("CC00FF00").
  • FromHsla-色相,饱和度和亮度双值,可选的alpha值(0.0-1.0).
  • FromRgb-红色,绿色和蓝色int值(0-255).
  • FromRgba-红色,绿色,蓝色和alpha整数值(0-255).
  • FromUint-设置表示argb的单个double值.
    • Named Colors - a collection of common named-colors, including Red , Green , and Blue .
    • FromHex - string value similar to the syntax used in HTML, eg "00FF00".
    • Alpha is can optionally be specified as the first pair of characters ("CC00FF00").
    • FromHsla - Hue, saturation and luminosity double values, with optional alpha value (0.0-1.0).
    • FromRgb - Red, green, and blue int values (0-255).
    • FromRgba - Red, green, blue, and alpha int values (0-255).
    • FromUint - set a single double value representing argb .
    • 参考:在Xamarin.Forms中使用颜色

      这篇关于使用Xamarin在XAML中指定RGB颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆