Value converters
In some cases, there are times when we need to data bind two properties of incompatible types. A Converter
is an object that converts the value from source to target and vice versa. Each converter must implement the IValueConverter
interface, which implements two functions, Convert
and ConvetBack
. We are going to create a converter that will take a bool
as the source, and simply return the opposite value to the value in the source.
The ConvertBack
method will only be used if the data binding is a TwoWay
binding.
In the Stocklist.XamForms
project, add a new folder called Converters
, and inside this folder create a new file called NotConverter.cs
, implement the following:
public class NotConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var b = value as bool?; if (b != null) { ...