我正在我的应用程序中创建一些应用程序样式,并希望通过键定义一些显式颜色.在
WPF XAML中,我将创建一个SolidColorBrush来定义RGB / ARGB值.在Xamarin XAML中,我是否需要将其转换为十六进制以在XAML中定义相同的颜色?下面的代码片段来自WPF XAML.
- <SolidColorBrush
- x:Key="blueColor">
- <SolidColorBrush.Color>
- <Color
- A="255"
- R="50"
- G="150"
- B="225" />
- </SolidColorBrush.Color>
- </SolidColorBrush>
解决方法
Xamarin.Forms提供了跨平台的Color类.
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
>命名颜色 – 常见命名颜色的集合,包括红色,绿色和蓝色.
> FromHex – 类似于HTML中使用的语法的字符串值,例如“00FF00”.
>可以选择将Alpha指定为第一对字符(“CC00FF00”).
> FromHsla – Hue,饱和度和光度双值,带可选的alpha值(0.0-1.0).
> FromRgb – 红色,绿色和蓝色int值(0-255).
> FromRgba – 红色,绿色,蓝色和alpha int值(0-255).
> FromUint – 设置一个表示argb的double值.