使用 Xamarin 在 XAML 中指定 RGB 颜色 [英] Specify a RGB color in XAML with Xamarin
问题描述
我正在我的应用程序中创建一些应用程序样式,并希望定义一些显式颜色以供按键使用.在 WPF XAML 中,我将创建一个 SolidColorBrush 来定义 RGB/ARGB 值.在 Xamarin XAML 中,我是否需要将其转换为十六进制以在 XAML 中定义相同的颜色?下面的代码片段来自 WPF XAML.
<SolidColorBrush.Color><颜色一个=255"R=50"G=150"B="225"/></SolidColorBrush.Color></SolidColorBrush>
Xamarin.Forms
提供了一个跨平台的 Color
类.
从 Xaml 使用:
还可以使用定义的颜色名称或此处显示的十六进制表示法在 Xaml 中轻松引用颜色:
<块引用>
Color 类提供了许多方法来构建颜色实例
- 命名颜色 - 一组常见的命名颜色,包括 Red 、 Green 和 Blue .
- FromHex - 类似于 HTML 中使用的语法的字符串值,例如00FF00".
- 可以选择将字母指定为第一对字符(CC00FF00").
- FromHsla - 色相、饱和度和亮度双值,带有可选的 alpha 值 (0.0-1.0).
- FromRgb - 红色、绿色和蓝色整数值 (0-255).
- FromRgba - 红色、绿色、蓝色和 alpha 整数值 (0-255).
- FromUint - 设置一个表示 argb 的双精度值.
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
provides a cross-platform Color
class.
Using from Xaml:
Colors can also be easily referenced in Xaml using the defined color names or the Hex representations shown here:
<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" />
The Color class provides a number of methods to build a color instance
- 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 .
Ref: Using Colors in Xamarin.Forms
这篇关于使用 Xamarin 在 XAML 中指定 RGB 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!