Hi everyone,
We're trying to have a clickable icon inside a ListView item, we're using MVVM architecture. The problem is that the specified Command binding is not being executed, and I'm at a loss for what to do. Nothing happens when I tap the image, and the breakpoints inside the command are not being hit.
The XAML looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Name="Page">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<Grid Padding="8,8,8,8">
<Grid.RowDefinitions>
<RowDefinition Height="5*"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="5*"></RowDefinition>
</Grid.RowDefinitions>
<ScrollView Grid.Row="0" Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill">
<StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill">
<p:Label Style="{StaticResource detailLabelStyle}" Text="OMSCHRIJVING" />
<p:Label Style="{StaticResource darkLabelStyle}" Text="{Binding Opdracht.Description}" />
<p:Label Style="{StaticResource detailLabelStyle}" Text="TOTAAL" />
<p:Label Style="{StaticResource darkLabelStyle}" Text="{Binding Opdracht.Price}" />
</StackLayout>
</ScrollView>
<Grid Grid.Row="1" BackgroundColor="{StaticResource PGreen}" Padding="0,1,0,1">
<AbsoluteLayout VerticalOptions="Fill" HorizontalOptions="Fill">
<BoxView Color="White"
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"/>
<p:Label Style="{StaticResource detailLabelStyle}" Text="ARTIKELEN" FontSize="Default"
AbsoluteLayout.LayoutBounds="4,3,.9,.9" AbsoluteLayout.LayoutFlags="SizeProportional"/>
</AbsoluteLayout>
</Grid>
<ListView Style="{StaticResource listViewStyle}"
Grid.Row="2"
ItemsSource="{Binding Opdracht.Articles}"
x:Name="OrdersListView"
HasUnevenRows="True"
VerticalOptions="Fill"
HorizontalOptions="Fill"
SelectedItem="{Binding SelectedItem, Mode=TwoWay}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell x:Name="viewCell">
<ViewCell.View>
<StackLayout Orientation="Vertical" VerticalOptions="Fill" HorizontalOptions="Fill">
<Image Source="abacus_large.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Path=BindingContext.ViewArticleMilestonesCommand, Source={x:Reference Page}}"
BindingContext="{x:Reference Page}"
CommandParameter="{Binding ExploreArticleResultLine}" />
</Image.GestureRecognizers>
</Image>
<p:Label Style="{StaticResource detailLabelStyle}" Text="OMSCHRIJVING"/>
<p:Label Style="{StaticResource darkLabelStyle}" Text="{Binding Description}"/>
<p:Label Style="{StaticResource detailLabelStyle}" Text="AANTAL"/>
<p:Label Style="{StaticResource darkLabelStyle}" Text="{Binding Amount}"/>
<p:Label Style="{StaticResource detailLabelStyle}" Text="STATUS"/>
<p:Label Style="{StaticResource darkLabelStyle}" Text="{Binding Status}" />
<p:Label Style="{StaticResource detailLabelStyle}" Text="PRIJS"/>
<p:Label Style="{StaticResource darkLabelStyle}" Text="{Binding Price}"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ContentPage>
And this is the Command part of the ViewModel:
public Command ViewArticleMilestonesCommand
{
get
{
if (_viewArticleMilestonesCommand != null)
return _viewArticleMilestonesCommand;
else
return _viewArticleMilestonesCommand = new Command
(async (a) =>
{
var article = a as ExploreArticleResultLine;
if (a == null) return;
var milestoneResponse = await _service.GetArticleMilestones(article.Id);
if (milestoneResponse.StatusCode != HttpStatusCode.OK || milestoneResponse.Object == null)
{
HandleException("Fout bij laden voortgangsgegevens", true);
return;
}
await NavigationService.PushAsync<ExplorerArticleMilestonesPage, ExplorerArticleMilestonesViewModel>
(
viewmodel =>
{
viewmodel.Milestones = (List<Milestone>)milestoneResponse.Object;
});
});
}
}
Any help would be greatly appreciated.