bindingmauicommunity-toolkit-mvvmmaui-markup-community-toolkit

.Net Maui using Community toolkit and Markup , how to bind Image Tapped to command in ViewModel


Hi everyone i do have a viewmodel that has a command

[RelayCommand]
public async Task InitializeLogin(CancellationToken token) {
    var toast = Toast.Make("InitializeLogin clicked", ToastDuration.Short, 14);
    await toast.Show(token);
}

Which creates a bindable command InitializeLoginCommand.

I would like it to trigger when i click on an Image

new Image()
    .Margin(new Thickness(10))
    .Aspect(Aspect.AspectFit)   
    .Column(Column.MyColumn),

How do i do this ? I really like the markup and i know how to bind properties of the object such as Label.Text or BoxView.BackgroundColorProperty, but i dont know how to do it when there is no direct CommandProperty

There is a .TapGesture but that would force me to inline the method like this

 new Image()
 .Margin(new Thickness(10))
 .Aspect(Aspect.AspectFit)
 .BindCommand()
 .TapGesture(async () => await Toast.Make("InitializeLogin clicked", 
  ToastDuration.Short, 14).Show(),2)
 .Column(Column.AicraImage),

is there some easy fix im missing ? Thanx


Solution

  • So i am blind after all.

    Just use BindTapGesture instead of TapGesture. Time to call it a day.