Xamarin.Formsにおける色指定の方法(C#、Xaml)


これはXamarin.Formsにおける色指定の方法です.

備忘録

Xamlでの色指定

Xamlで色指定する場合は、ビルトインの色名、RGB値、アルファ値(透明度)つきRGB、TinyRGB、アルファ値つきTinyRGBで指定できる。

        <Label Text="Sea color" BackgroundColor="Aqua" />
        <Label Text="RGB" BackgroundColor="#00FFFF" />
        <Label Text="Alpha plus RGB" BackgroundColor="#2200FFFF" />
        <Label Text="Tiny RGB" BackgroundColor="#0FF" />
        <Label Text="Tiny Alpha plus RGB" BackgroundColor="#C0FF" />

C#での色指定

C#でも同じように色名(構造体)や16進表記(文字列)で指定できる。

            var label = new Label();
            label.BackgroundColor=Color.Aqua;
            label.BackgroundColor = Color.FromHex("#00FFFF");
            label.BackgroundColor = Color.FromHex("#2200FFFF");
            label.BackgroundColor = Color.FromHex("#0FF");
            label.BackgroundColor = Color.FromHex("#20FF");

他にも

            label.BackgroundColor = Color.FromRgb(0x00, 0xff, 0xff);
            label.BackgroundColor = Color.FromRgb(0x00, 0xff, 0xff,0x22);