【问题标题】:[Layout].Children.Clear() or Remove() gives error in Xamarin.Forms[Layout].Children.Clear() 或 Remove() 在 Xamarin.Forms 中给出错误
【发布时间】:2016-01-20 23:58:58
【问题描述】:

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

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

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

【问题讨论】:

  • 您可以检查任何已知的 Xamarin.Forms 错误Here
  • 当您在子控制器中添加事件并且有一些东西为空对象引用时,会发生此错误。

标签: xamarin.forms


【解决方案1】:

我没有使用 Scroll View 的 Children 属性,我使用了 Content 并删除了我之前使用的布局:

StackLayout mainView = new StackLayout();

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

因此,例如,您要清除的是 mainView 而不是我想的 ScrollView。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-21
    • 2017-08-10
    • 2022-07-29
    • 1970-01-01
    • 2014-04-25
    相关资源
    最近更新 更多