Search code examples
xamarinxamarin.formsxamarin.iosxamarin.androidmvvmcross

How can I assign Hex or RGB color to the MvxColor in Android Converter


I have converter like below in that I want to return my own Hex or RGB color.

In iOS

public class PinkSelectedWhiteUnselectedValueConverter : MvxValueConverter<bool, UIColor> {
    UIColor purePink = UIColor.FromRGB(233, 60, 172);
protected override UIColor Convert(bool value, Type targetType,object parameter, CultureInfo culture) {
    return (bool)value ? purePink : UIColor.White;
  }
}

it's working fine

But in Android, it's not working

 public class PinkSelectedWhiteUnSelectedValueConverter : MvxValueConverter<bool, Color> {
     
  Color colorPink = (Color)new  System.Drawing.ColorConverter().ConvertFromString("#e93cac");
  

   protected override Color Convert(bool value, Type targetType, object parameter, CultureInfo culture) {
          
  return (bool)value ? colorPink : Color.White;
        
   }
   
 }

Please help me on that thanks in advance.


Solution

  • What you are looking for is something like this :

    Color colorPink = Android.Graphics.Color.ParseColor("#e93cac");
    

    or else something like this

    Color purePink = Color.Rgb((int)r,(int) g,(int) b)