How to call any Navigation.PushPopupAsync from CustomViewCell in Xamarin Form?

I have a ListView and which is having CustomViewCell. CustomViewCell having few buttons.

Button: ShowProfile: This button popup another page. The problem is I don't know how to Navigation.PushPopupAsync in CustomViewCell. I also need to pass current CustomViewCell details in that.

This is example how I use Navigation.PushPopupAsync in another page which is working fine but doesn't work in case of CustomViewCell.

Navigation.PushPopupAsync(new UserProfilePage(new ExtendedProfile(_viewModel.Profile)));

But above code doesn't work in CustomViewCell.

public partial class ProfileListItemViewCell : CustomViewCell
{
    public ProfileListItemViewCell()
    {
        InitializeComponent();
    }

    protected override void OnBindingContextChanged ()
    {
        base.OnBindingContextChanged ();
    }
    private void MenuItemProfile_Clicked(object sender, System.EventArgs e)
    {
        //not working
        Navigation.PushPopupAsync(new UserProfilePage(new ExtendedProfile(_viewModel.Profile)));
    }
}

Please suggest

Answers

  • Xami3Xami3 PKMember, University ✭✭✭

    @developer007 you have few options here
    1. either pass the navigation object from your page to you list items and then call the pushAsync etc on that object from you custom cell.
    2. introduce navigation/INavigation on app.cs/app.xaml.cs and use that from your custom cell
    3. create an event on you viewcell/Viewmodel item and let you viewmodel/page subscribe to that event. and call the navigation from your page or viewmodel

Sign In or Register to comment.