I have a ListView as follows
<ListView
Grid.Row="0"
Margin="0"
x:Name="ItemsListView"
ItemsSource="{Binding SourceItems}"
VerticalOptions="FillAndExpand"
HasUnevenRows="false"
RefreshCommand="{Binding LoadItemsCommand}"
IsPullToRefreshEnabled="true"
IsRefreshing="{Binding IsBusy}"
ItemSelected="OnItemSelected"
IsVisible="{Binding ShowListView}"
RowHeight="55">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
Margin="15,0,0,0"
Padding="0"
RowSpacing="0"
ColumnSpacing="0">
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width="1*" />
<ColumnDefinition
Width="7*" />
<ColumnDefinition
Width="1*" />
<ColumnDefinition
Width="1*" />
</Grid.ColumnDefinitions>
<Image
VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"
HeightRequest="35"
WidthRequest="35"
Grid.Row="0"
Grid.Column="0"
Aspect="AspectFit"
Source="{Binding Icon}">
</Image>
<StackLayout
VerticalOptions="CenterAndExpand"
Spacing="0"
CompressedLayout.IsHeadless="true"
Margin="15,0,0,0"
Grid.Row="0"
Grid.Column="1">
<Label
VerticalTextAlignment="Start"
Text="{Binding Name}"
FontAttributes="Bold"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemTextStyle}"
FontSize="16" />
<Label
VerticalTextAlignment="Start"
Text="{Binding Description}"
LineBreakMode="NoWrap"
Style="{DynamicResource ListItemDetailTextStyle}"
FontSize="13" />
</StackLayout>
<Image
Grid.Row="0"
Grid.Column="3"
HeightRequest="20"
WidthRequest="20"
VerticalOptions="CenterAndExpand"
HorizontalOptions="StartAndExpand"
Aspect="AspectFit"
Source="{Binding Icon}" />
<Image
BackgroundColor="Lime"
Grid.Row="0"
Grid.Column="2"
InputTransparent="false"
Margin="0,0,10,0"
HeightRequest="20"
WidthRequest="20"
VerticalOptions="CenterAndExpand"
HorizontalOptions="StartAndExpand"
Aspect="AspectFit"
Source="ic_two">
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding OnFavouriteCommand}"
CommandParameter="{Binding .}"
NumberOfTapsRequired="1">
</TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
and in my ViewModel I have
public ICommand OnFavouriteCommand { get; set; }
public MyViewModel()
{
OnFavouriteCommand = new Command<Object>(OnFavourite);
}
void OnFavourite(Object ob)
{
Debug.WriteLine(ob);
}
I don't get a Break Point
hit on OnFavourite
. I can't figure out what am I missing here? The idea was to get a gesture recognizers attached to each image and pass down the item bound to that row only.
I've just noticed, if I bring
<Image
BackgroundColor="Lime"
Grid.Row="1"
InputTransparent="false"
Margin="0,0,10,0"
HeightRequest="20"
WidthRequest="20"
VerticalOptions="CenterAndExpand"
HorizontalOptions="StartAndExpand"
Aspect="AspectFit"
Source="ic_favourites">
<Image.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding OnFavouriteCommand}"
CommandParameter="{Binding .}"
NumberOfTapsRequired="1">
</TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
Out side of the ListView
the break point does get hit!. Left me scratching my head... :|