Android. Navigate from custom view renderer to another Page in xamarin forms project

Jakob Aagesen 1 Reputation point

i have made a custom view renderer for my Android project. It almost works. I have a problem navigating away from it.
I have a button in my custom view that should navigate to another page located in the xamarin forms project.

Using events, I can call methods in the xamarin form page, that hosts the custom view, from the custom vew renderer.
I have then tried, from there to call:

await Application.Current.MainPage.Navigation.PushAsync(new NewPage());   

to navigate to the new page, but i get the following error:

  Message=No view found for id 0x1 (unknown) for fragment FragmentContainer{e25dddc} (64107200-e440-448f-a9b5-9de8079f1cdf id=0x1)  

I don't know what it means and how to fix it. There really isn't much information to find anywhere, so i'm hoping that someone here can help me out.

in OnElementChanged i save the xamarin Form view:

videoRoom = e.NewElement as VideoRoomView;  

and from a button in the custom view:

var closeButton = this.Context.GetActivity().FindViewById<Android.Widget.Button>(Resource.Id.close_button);  
closeButton.Click += CloseButton;  

I call the xamarin form CloseRoom method:

private void CloseButton(object sender, EventArgs e)  

That will call a method in the xamarin Form view:

public void CloseRoom()  
    CloseEvent?.Invoke(this, null);  

The event is handled by the Xamarin Page that is hosting the custom view:

private void VideoRoomView_CloseEvent(object sender, EventArgs e)  
private async void Close()  
    await Application.Current.MainPage.Navigation.PushAsync(new NewPage());  

Please let me know, if any of this is unclear.

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,818 questions
{count} votes