[Layout].Children.Clear()或Remove()在Xamarin.Forms中给出错误

[Layout].Children.Clear()或Remove()在Xamarin.Forms中给出错误,xamarin.forms,Xamarin.forms,我在表单中使用绝对布局作为ContentView的内容。我在AbsoluteLayout中添加了另一个ContentView,当我想清除子项或删除任何子项时,我会得到ObjectReferenceException。这是已知的Xamarin形式的bug吗?以下是给出错误的代码: var scrollView = new ScrollView (); absoluteLayout.Children.Insert (0, scrollView); absoluteLayout.Children.Re

我在表单中使用绝对布局作为ContentView的内容。我在AbsoluteLayout中添加了另一个ContentView,当我想清除子项或删除任何子项时,我会得到ObjectReferenceException。这是已知的Xamarin形式的bug吗?以下是给出错误的代码:

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

我在代码中使用了Insert/RemoveAt,但当我同时使用Add/Clear时会发生错误。

我没有使用滚动视图的Children属性,我使用了内容并删除了我使用的以前的布局:

StackLayout mainView = new StackLayout();

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

例如,我想您要清除的是主视图而不是滚动视图。

您可以检查任何已知的Xamarin。表单错误当您在子控制器上添加了事件并且存在空对象引用时,就会发生此错误。