476rick
476rick

Reputation: 2795

Xamarin.Forms controls disappear when navigate back to a page on Android

I'm building an application with Xamarin.Forms and a Portable Class Library. The app can be used on Android, iOS and UWP.

I made a page that works correct on each platform:
enter image description here

After clicking an item in the ListView, a new page will be opened:

Navigation.PushAsync(new CourseInfoPage(ID));

When that page is opened and I press the "Back-button" and navigate back to the page shown above, it looks like this: enter image description here

So some controls disappear when I'm navigating (away and then) back to this page. This ONLY happens on Android. If I click somewhere in the white area, the controls still function but I don't get to see them.

What did I try:

protected override void OnAppearing()
{
    base.OnAppearing();
    Content = getContentPage();
}


protected override void OnDisappearing()
{
    base.OnDisappearing();
    this.Content = null;
}

But this doesn't solve the problem.

How do I fix this? What is the problem?

Upvotes: 2

Views: 3851

Answers (3)

kudzanayi
kudzanayi

Reputation: 101

My issue was that I was generating views from code (which I have to), so for example in page1.xaml I would have a stacklayout with an x:name that I would then populate the children with views via code (generated from a singleton), then when I navigate to page2.xaml I would have another stacklayout that I would populate with views from the same singleton (sometimes with changes). To solve it was messy, I basically created two properties on the singleton that had the views, so when page1's stacklayout gets populated, it received singleton.Views and when I navigate to page2, it would get singleton.ViewsOther, page3 => singleton.Views, page3 => singleton.ViewsOther... and so on. Its messy, but I just needed it to work, you can get a better solution from experts, but just in case this helps someone else who needs a quick fix

Upvotes: 0

Kuba
Kuba

Reputation: 226

If you want to go back to previous Page you can use

PopAsync()

or

PopModalAsync()

Grab some informations about Xamarin.Forms Navigation here :) https://developer.xamarin.com/api/type/Xamarin.Forms.INavigation/

Upvotes: 1

Mario Galván
Mario Galván

Reputation: 4032

This is a weird issue, are you doing something with the view on the next Page? You can always double check the visibility of the view:

protected override void OnAppearing()
{
    base.OnAppearing();
    YourView.IsVisible = true;
}


protected override void OnDisappearing()
{
    base.OnDisappearing();
    YourView.IsVisible = true;
}

If that does not work, use BackgroundColor property to detect which of the views is doing this weird issue, maybe for some reason the color's are being changed.

Upvotes: 1

Related Questions