Élodie Petit
Élodie Petit

Reputation: 5914

[Layout].Children.Clear() or Remove() gives error in Xamarin.Forms

I use an AbsoluteLayout in my form as the Content of a ContentView. I add another ContentView in AbsoluteLayout and when I want to clear the children or remove any children I get ObjectReferenceException. Is this a known bug of Xamarin Forms? Here is the code that gives the error:

var scrollView = new ScrollView ();
absoluteLayout.Children.Insert (0, scrollView);
absoluteLayout.Children.RemoveAt (0);

I used Insert/RemoveAt in the code but the error happens when I also use Add/Clear.

Upvotes: 1

Views: 3333

Answers (1)

Mario Galván
Mario Galván

Reputation: 4032

I haven't use Children property of a Scroll View, I have used the Content and to remove the previous layout I use:

StackLayout mainView = new StackLayout();

ScrollView scView = new ScrollView{
    Content = mainView,
};

So for instance what you want to wipe out is the mainView not the ScrollView I suppose.

Upvotes: 1

Related Questions