Command binding not working inside Listview in Xamarin Forms

tutugeorgetutugeorge USMember ✭✭

I am trying to bind a command to TapGesture to a Frame inside the list view control. Frame is defined inside the datatemplate for the list view.

<ListView.ItemTemplate>



<Grid.ColumnDefinitions>


</Grid.ColumnDefinitions>

<Frame.GestureRecognizers>

</Frame.GestureRecognizers>




</ListView.ItemTemplate>

Here LstSrc and GoToPageCommand ae defined in the viewmodel class. And Item1 is defined inside LstSrc.

Delegate Command defined inside view model is
public DelegateCommand GoToPageCommand => new DelegateCommand(
async s => {
await _navigationService.NavigateAsync("NextPage");
});

But on tapping, the control is not coming to the command method.

Best Answer

Answers

  • NMackayNMackay GBInsider, University mod
  • CharwakaCharwaka INMember ✭✭✭✭

    @NMackay said:
    @tutugeorge

    You need to use relative source binding, add an x:Name attribute to your page and reference it in your command

    @NMackay Any idead How Can we do same from App.xaml ,

    let say i am setting my page name as x:Name="Dashboard",but my datatemplate is in app.xaml resources so how do i x:Reference this now ?

    Thanks!

  • NMackayNMackay GBInsider, University mod

    @Charwaka said:

    @NMackay said:
    @tutugeorge

    You need to use relative source binding, add an x:Name attribute to your page and reference it in your command

    @NMackay Any idead How Can we do same from App.xaml ,

    let say i am setting my page name as x:Name="Dashboard",but my datatemplate is in app.xaml resources so how do i x:Reference this now ?

    Thanks!

    I honestly don't know if that is supported in XAML, WPF caters for this but I'm really not sure for regarding Xamarin Forms.

  • CharwakaCharwaka INMember ✭✭✭✭
    edited February 15

    @NMackay said:

    @Charwaka said:

    @NMackay said:
    @tutugeorge

    You need to use relative source binding, add an x:Name attribute to your page and reference it in your command

    @NMackay Any idead How Can we do same from App.xaml ,

    let say i am setting my page name as x:Name="Dashboard",but my datatemplate is in app.xaml resources so how do i x:Reference this now ?

    Thanks!

    I honestly don't know if that is supported in XAML, WPF caters for this but I'm really not sure for regarding Xamarin Forms.

    Thanks for quick reply

    i am trying something like this

    <views:HomePage x:Key="HomePageView"/>

    But not working.

Sign In or Register to comment.