This time, I want to share with you this great feature. Let me tell you something, when I saw this functionality I really LOVED IT ? !!! Because I can play with the colors! ?
In this post, we will be learning about the different functionalities that Xamarin Essentials bring to in the System.Drawing.Color libra
? Using color formats
? Transforming color aspects
First of all… What do I need?
- Add from NuGet Package the plugin: Xamarin.Essentials
You can read more information about Xamarin Essential here.
Let’s start!!!
Using color formats
Xamarin Essential created the ColorConverts class for us. With this class we can convert the colors to different types. We can use the following:
▪ FromHex ➡ Receives a string as a Hexadecimal value.
▪ FromHls ➡ Receives three float values as parameters: Hue, Saturation and Luminosity.
▪ FromHsla ➡ Receives three float values as parameters: Hue, Saturation and Luminosity. And one parameters as an Int value: Alpha.
Transforming color aspects
This is my favorite topic ?. System.Drawing.Color
? WithAlpha ? WithLuminosity
? WithHue ? WithSaturation
? AddLuminosity
To use it, you just must call the color extension type you just add the color next to the extension wished.
Let’s see an example in codeLet’s see a simple example
In the following example, I used the same color with difference changes of color extensions but with the same value as parameter ( 30 ), with this way we can appreciate the difference.
XAML
C# code
Spanish version: https://medium.com/@reyes.leomaris/convirtiendo-colores-en-xamarin-forms-bf7d2a691291
Thanks for reading! ?
You saved my life, I needed this to fix some labels in dark / light mode.
I come from angular / react JS, I am new to xamarin.
Thanks a lot!!
🙈 It’s a pleasure for me!