For a single input in .cs file
public class QuesSeriesIndicatorValueConverter : MvxValueConverter<bool, int>
{
protected override int Convert(bool value, Type targetType, object parameter, CultureInfo culture)
{
if (value)
{
return Resource.Drawable.up_arrow;
}
else
{
return Resource.Drawable.down_arrow;
}
}
protected override bool ConvertBack(int value, Type targetType, object parameter, CultureInfo culture)
{
return base.ConvertBack(value, targetType, parameter, culture);
}
}
From xml I pass data as
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:gravity="center"
android:layout_gravity="center"
android:padding="2dp">
<MvxImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginRight="2dp"
android:gravity="center"
android:layout_gravity="center"
local:MvxBind="DrawableId QuesSeriesIndicator(questionState)" />
</LinearLayout>
Now For an input Where I need to pass two parameters in Xml, I found out we can use Tuple.
Ex:: public class CruiseShipIndicatorValueConverter : MvxValueConverter<Tuple<bool, bool>, int>
How to pass the Data in Xml, similar to
local:MvxBind="DrawableId QuesSeriesIndicator(questionState)"
You can send an object that have the properties that you need, also you converter can be type object, instead int/string/bool, also the value is better if you use an object and cast to the value that you need and return the object(string/int/bool or that you wanted);