Introduction
With the introduction of Xamarin Essentials APIs, the developer's task of creating dependency services for many of the features like Map, GPS, battery, etc. has become simpler with minimal code changes. Xamarin Essential is a package that contains abstractions for platform-specific features such as an accelerometer, barometer, ColorConverter, compass, connectivity and many more. One good part is that it comes pre-packaged with Visual Studio 2019's latest builds and included as a default Nuget package when a new Xamarin forms solution is created. We will discuss an API called ColorConverter below.
Color Converter
The color converter API helps to convert System.drawing Color to platform specific colors like Android, iOS, and Windows. Below is a step by step tutorial for the usage of the API.
Step 1: Create a new Xamarin forms solution and name it ColorConverterDemo (Users can name it as per their choice).
Step 2: Open the MainPage.Xaml and add the Label and Button as shown below. We are going to change the color of the label by making use of the Color Converter API. Observe the code behind the changes in the second image.
Step 3: With a press of the button, the label color will be changed to Green and we can see the ColorConverter methods. The commented section is for the reader to play around with API overloads.
Step 4: Demo of the app
Before Button click:
After Button click:
Conclusion
With Color converter, developers need not write the IValueConverter interface. I have uploaded the sample project which I used in the demonstration. Comments. Feedback is welcome!