MvvmCross/MvvmCross — pull request #549 by damirarh (2014-01-12 11:14:14+00:00)
Title: Access to IMvxValueConverter from native wrapper

Hi,

I added a protected read-only property to `MvxNativeValueConverter` to provide access to the wrapped protable `IMvxValueConverter`.

With this change it is possible to create portable converters with public properties which can be used configure the behavior of converters. A simple example:

public class BoolToTextConverter : MvxValueConverter
{
public string TrueValue { get; set; }
public string FalseValue { get; set; }

protected override string Convert(bool value, Type targetType, object parameter, CultureInfo culture)
{
return value ? TrueValue : FalseValue;
}
}

The native wrapper can now look like this:

public class NativeBoolToTextConverter :
MvxNativeValueConverter
{
public string TrueValue
{
get { return Wrapped.TrueValue; }
set { Wrapped.TrueValue = value; }
}

public string FalseValue
{
get { return Wrapped.FalseValue; }
set { Wrapped.FalseValue = value; }
}
}

This is how it would be instantiated in XAML:

For other binding modes one can always create derived converters which initialize the properties in their constructor as required:

public OnOffConverter : BoolToTextConverter
{
public OnOffConverter
{
TrueValue = "On";
FalseValue = "Off";
}
}