In the Xamarin wpf project, when clicking on the button, command is not working.
I have a button in the datatemplate of a listview item template and a command has been binded to this button. This is as shown below :
<ListView x:Name="lstView" ItemsSource="{Binding Foods}" HorizontalOptions="End" RowHeight="150">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="2">
<Grid.RowDefinitions>
<RowDefinition Height="" />
<RowDefinition Height="" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding FoodImage}" Grid.Column="0" Grid.RowSpan="3" HeightRequest="100"
WidthRequest="100" />
<Label Text = "{Binding FoodName}" Grid.Column="1" Grid.Row="0" FontSize="15" />
<StackLayout Orientation="Horizontal" Grid.Column="1" Grid.Row="1">
<Label Text = "{Binding Price}" FontSize="15" WidthRequest="60" />
<Editor Text="{Binding Quantity}" Keyboard="Numeric" Placeholder="Quantity" MaxLength="3"
HeightRequest="30" IsSpellCheckEnabled="False"
WidthRequest="50" Margin="2" IsTextPredictionEnabled="False" />
<Button Text="+ to Cart" Command="{Binding AddToCartCommand}" HeightRequest="30" WidthRequest="100"
BackgroundColor="Black" TextColor="White" />
<Button Text="X" Command="{Binding OrderClearCommand}" HeightRequest="30" WidthRequest="40"
BackgroundColor="Black" TextColor="White" />
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
And in my viewmodel class, i have the code for this :
public ICommand AddToCartCommand
{
get;
}
And in the constructor of this viewmodel class, i have the code like this :
AddToCartCommand = new Command(AllCalculate);
----------------------------------------------
void AllCalculate()
{
Prices = 100;
Application.Current.MainPage.DisplayAlert("Total", "Hai", "ok");
}
Why the button command is not triggering when button is clicked ?
I am using VS2019.