I want to Show/Hide a button dependant on the value of the BindingContext of the ListView item so I made a ValueConverter to convert the BindingContext to a boolean value. For some reason it's not working and the button is always visible even when the value is null.
EDIT: When initializing the converter returns the right value, true/false but the IsVisible is not set it seems. When changing the item the binding is bound to the Convert method is not called again, this also feels strange to me as I want it to update whenever the object it is bound to has changed value.
Here's the converter:
public class NullToBoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null ? true : false;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
//Not used.
throw new NotImplementedException();
}
}
And here's how I'm using it in XAML:
<converters:NullToBoolConverter x:Key="objectToBool" />
<DataTemplate x:Key="MyItemTemplate">
<ViewCell>
<Grid ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<controls:ImageButton Grid.Column="0"
IsVisible="{Binding Path=., Converter={StaticResource objectToBool}}"
VerticalOptions="Start" HorizontalOptions="Center"
Image="ic_remove_circle_outline_black_24dp"
BackgroundColor="Transparent" />
</Grid>
</ViewCell>
</DataTemplate>
And the listview itself for what it's worth
<ListView ItemsSource="{Binding MyItems}"
ItemTemplate="{StaticResource MyItemTemplate}"
RowHeight="50"
HeightRequest="155"
VerticalOptions="Start"
BackgroundColor="#209FAA9F"/>