What is Happening:
- I am passing one boolean value to a converter and performing some action(Changing Drawable).
What I am trying to do:
- How to pass two boolean values to a converter and perform some action.
- Is this possible How ?
- If this is not the right approach by passing two inputs to a single value converter, then how to resolve this
CONVERTER
: CruiseShipIndicatorValueConverter.cs
public class CruiseShipIndicatorValueConverter : 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);
}
}
XML
<?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>
You can try to either encapsulate the two booleans to a class or use Tuple.
A sample class implementation for you would be something like this.
Read more about Tuples here.
Its very simple. This can be easily done with single value converter. Instead of using tuple or any other generic data type, we can do this by existing converter definition.
For example:
where MvxValueConverter, bool(questionState1) is the "value" in Convert and int is the return type in Convert. For second bool value(questionState2), get that in "parameter" as type object.
For binding, we have to send