Unlike the behavior on windows platform my search handler does not trigger my command method on android platform
I tried putting gesture recognizers, but this does not work too.
Method "SelectGymCommand" on my viewmodel class adds the selected item to the SelectedGyms list which is binded to listview. This works perfectly on windows plataform, but in android plataform the listview is not updated.
> `<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:utils="clr-namespace:BehaviorMauiApp.Utils"
xmlns:viewModel="clr-namespace:BehaviorMauiApp.ViewModel"
xmlns:model="clr-namespace:BehaviorMauiApp.Model"
x:Class="BehaviorMauiApp.View.FitnessPage"
x:DataType="viewModel:GymViewModel"
Title="FitnessPage">
> <Shell.SearchHandler>
> <utils:SearchGymHandler
x:Name="searchGymHandler"
GymToSearch="{Binding ListGym}"
Placeholder="pesquisar"
Command="{Binding SelectGymCommand}"
CommandParameter="{Binding Source={x:Reference searchGymHandler}, Path=SelectedItem}">
> <utils:SearchGymHandler.ItemTemplate>
> <DataTemplate x:DataType="model:Gym" >
> <Grid Padding="8" RowDefinitions="*">
> <Label Margin="8" TextColor="Gray" Text="{Binding Description}" >
> </Label>
> </Grid>
> </DataTemplate>
> </utils:SearchGymHandler.ItemTemplate>
> </utils:SearchGymHandler>
> </Shell.SearchHandler>
> <VerticalStackLayout>
> <Image Aspect="Center" Margin="0,32,0,0" Source="outline_fitness_center_white_48dp.png" />
> <ListView ItemsSource="{Binding SelectedGyms}">
> <ListView.ItemTemplate>
> <DataTemplate x:DataType="model:Gym">
> <ViewCell>
> <Label Margin="8" TextColor="Gray" Text="{Binding Description}"></Label>
> </ViewCell>
> </DataTemplate>
> </ListView.ItemTemplate>
> </ListView>
> </VerticalStackLayout>
> </ContentPage>`
SearchGymHandler
namespace BehaviorMauiApp.Utils;
public class SearchGymHandler : SearchHandler
{
public static BindableProperty GymToSearchProperty = BindableProperty.Create(
nameof(GymToSearch), typeof(List<Gym>), typeof(SearchGymHandler),new List<Gym>());
public List<Gym> GymToSearch
{
get => (List<Gym>)GetValue(GymToSearchProperty) ;
set => SetValue(GymToSearchProperty, value);
}
protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);
ItemsSource = GymToSearch.Where(a => a.Description.Contains(newValue, StringComparison.OrdinalIgnoreCase)).ToList();
}
}
ViewModel
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.Windows.Input;
namespace BehaviorMauiApp.ViewModel;
public class GymViewModel : ObservableObject
{
List<Gym> listGym;
public List<Gym> ListGym
{
get => listGym; set
{
listGym = value;
OnPropertyChanged();
}
}
public ObservableCollection<Gym> SelectedGyms { get; }
public ICommand SelectGymCommand { get; }
public GymViewModel(RestService restService)
{
ListGym = restService.GetGymList();
SelectGymCommand = new AsyncRelayCommand<Gym>(Select);
SelectedGyms = new();
}
private Task Select(Gym selectedGym)
{
SelectedGyms.Add(selectedGym);
return Task.CompletedTask;
}
}