The EventToCommand behavior doesn't trigger the button clicked event, in list view. In the attached sample we have a list view and added a grid as a DataTemplate for list view and i have added a button inside the grid and triggered the clicked event by using the EventToCommand behavior but the event doesn't fired.
The button clicked event shout fired when we tap on the button.
The event doesn't fired as expected.
Sample link attached
Out of curiosity, why don't you use the button command property instead of the behavior?
<Button Text="{Binding Name}" TextColor="#000000" InputTransparent="False" Command="{Binding ButtonClickedCommand}" />
This appears to be same issue as here: https://github.com/xamarin/Xamarin.Forms/issues/5414
The BindingContext of a cell is set to the relevant member of the ItemsSource. So, in the same way {Binding Name} is looking for the Name property on Person, {Binding ButtonClickedCommand} is looking for the ButtonClickedCommand property on Person.
One way to fix this is to add an x:Name to the page ( x:Name="Page" for instance) and change the binding to:
{Binding Source={x:Reference Page}, Path=BindingContext.ButtonClickedCommand}
This problem will still happen if you use the Button command directly (which you should probably do too).
@GalaxiaGuy Thank you for your suggestion it works as expected after applying your suggestion. Thanks for your help.
Most helpful comment
This appears to be same issue as here: https://github.com/xamarin/Xamarin.Forms/issues/5414
The
BindingContextof a cell is set to the relevant member of theItemsSource. So, in the same way{Binding Name}is looking for theNameproperty onPerson,{Binding ButtonClickedCommand}is looking for theButtonClickedCommandproperty onPerson.One way to fix this is to add an
x:Nameto the page (x:Name="Page"for instance) and change the binding to:{Binding Source={x:Reference Page}, Path=BindingContext.ButtonClickedCommand}This problem will still happen if you use the Button command directly (which you should probably do too).