How to implement the TextChanged the CommunityToolkit MVVM way

I am using the .Net Maui’s community toolkit and have some mvvm binding going on in a project.

I have a collectionview and a Searchbar connected to a ViewModel. I wish to implement the Searchbar’s is TextChanged, but with no luck.

it is saying,

Event “Textchanged” can only be bound to properties of delegate type ‘EventHandler’1’

I saw this Solution here on stack overflow, I however am using the COmmunityToolkit.

Xaml Code

public partial class CommunityPostsPagesViewModel : 
ObservableObject
{


private readonly ISecureStorageService _secureStorage;
private readonly IAppSettingGeneratorService _appsettingGenerator;
private readonly ICommunityPostCoreApiService 
 _communitypostService;
private readonly IClientCryptoGraphy _cryptoGraphy;
public CommunityPostsPagesViewModel(ISecureStorageService storage, 
ICommunityPostCoreApiService communitypostService
    , IAppSettingGeneratorService appsettingGenerator, 
IClientCryptoGraphy cryptoGraphy)
{
    _secureStorage = storage;
    _communitypostService = communitypostService;
    _appsettingGenerator = appsettingGenerator;
    _cryptoGraphy = cryptoGraphy;
    GetLastestComunityPost();
}


[ObservableProperty] 
string serchText;

[ObservableProperty]
ObservableCollection<ComunityPostsModel> comunityPosts;

[RelayCommand]
async void SearchTextChanged()
{
    ComunityPosts.Clear();
    var output = new ObservableCollection<ComunityPostsModel>();
    try
    {
        var apiResponse = await _communitypostService.GetAll();
        var searchResponse = apiResponse.Response.Where(m => 
               m.Title.ToLower().Contains(SerchText.ToLower()));
        if (!searchResponse.Any())
        {
            await Shell.Current.DisplayAlert("Oops!", $"There are 
                    currently no available community post with 
                     name: {SerchText}", "Ok");
            return;
        }
        else
        {
            foreach (var response in searchResponse)
            {
                output.Add(new ComunityPostsModel()
                {
                    DatePosted = response.DatePosted,
                    Body = response.Body,
                    Id = response.Id,
                    Title = response.Title

                });
            }
        }
    }
    catch (Exception ex)
    {

        await Shell.Current.DisplayAlert("Oops!", "Could not get 
   any comunity Post", "Ok");
    }
    ComunityPosts = output;
}

[RelayCommand]
async void ComunityPostSelected(ComunityPostsModel input)
{


    await Shell.Current.GoToAsync(nameof(CommunityPostPage), true, 
           new Dictionary<string, object>{
        {nameof(ComunityPostsModel),input}

    });

}

private async Task GetLastestComunityPost()
{
    var output = new ObservableCollection<ComunityPostsModel>();
    try
    {
        var apiResponse = await _communitypostService.GetAll();
        foreach (var response in apiResponse.Response)
        {
            output.Add(new ComunityPostsModel()
            {
                DatePosted = response.DatePosted,
                Body = response.Body,
                Id = response.Id,
                Title = response.Title
            });
        }
    }
    catch (Exception ex)
    {


    }

    ComunityPosts = output;
}

}

For the Xaml

<?xml version="1.0" encoding="utf-8" ?>
        <ContentPage 
         xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="AE.Pages.CommunityPostsPage"
         Title="Community Beta"
          xmlns:viewmodel ="clr-namespace:AE.ViewModels"
        x:DataType="viewmodel:CommunityPostsPagesViewModel"
          xmlns:itemViewModel ="clr-namespace:AE.Models"
       xmlns:ur="http://schemas.enisn- 
       projects.io/dotnet/maui/uraniumui/material"
         >

  <StackLayout Orientation="Vertical"
           Margin="25" Padding="25"
           >


<StackLayout>

  <SearchBar SearchCommand="{Binding SearchTextChangedCommand}" 
             Placeholder="Search Comunity Posts by Title" Text=" 
 {Binding SerchText}" 
             IsSpellCheckEnabled="True" TextChanged="{Binding 
  SearchTextChangedCommand}" Margin="00,00,00,25"/>
  <CollectionView ItemsSource="{Binding ComunityPosts}" >
    <CollectionView.ItemTemplate >
      <DataTemplate x:DataType="{x:Type 
   itemViewModel:ComunityPostsModel}" >
        <SwipeView  >
          <Frame>
            <Frame.GestureRecognizers>
              <TapGestureRecognizer Command="{Binding Source= 
  {RelativeSource AncestorType={x:Type 
    viewmodel:CommunityPostsPagesViewModel}}, 
  Path=ComunityPostSelectedCommand}" CommandParameter="{Binding .}" 
    />
            </Frame.GestureRecognizers>
            <StackLayout>
              <Label Text="{Binding Title}" FontFamily="Bold"/>
              <Label Text="{Binding DatePosted}" 
  FontSize="Caption"/>
            </StackLayout>
          </Frame>
        </SwipeView>
      </DataTemplate>
    </CollectionView.ItemTemplate>
  </CollectionView>


</StackLayout>

3

You can use EventToCommandBehavior of CommunityToolkit to bind Command:

<SearchBar ....>
   <SearchBar.Behaviors>
       <toolkit:EventToCommandBehavior
                EventName="TextChanged"
                Command="{Binding TextChangedCommand}" />
   </SearchBar.Behaviors>
</SearchBar>

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật