I've the next converter code like the example in this post Xamarin.Forms Binding Converter but when the value come in method only have the property Path="DeviceHasScanner" and the Binding property never is called :(
public class BoolToObjectConverter<T> : IValueConverter
{
public T TrueObject { set; get; }
public T FalseObject { set; get; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value ? TrueObject : FalseObject;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((T)value).Equals(TrueObject);
}
}
And I'm try implement it on this way:
<Image HorizontalOptions="Center" WidthRequest="200">
<Image.Source>
<Binding Source="{Binding DeviceHasScanner}">
<Binding.Converter>
<converters:BoolToObjectConverter x:TypeArguments="x:String" TrueObject="presstoscan.png" FalseObject="scanwithcamera.png" />
</Binding.Converter>
</Binding>
</Image.Source>
</Image>
And the boolean binding property in viewmodel is:
public bool DeviceHasScanner
{
get
{
return Settings.Get.DeviceHasScanner; //This code return true or false
}
}
