Xamarin.Forms将ScrollView添加到ContentPage并包装现有内容

时间:2019-07-10 14:42:09

标签: xaml xamarin xamarin.forms scrollview

我有一个用Xamarin.Forms编写的.xaml页面,仅在iOS平台上,我试图将页面的内容包装在ScrollView中,以解决显示键盘时调整大小的问题。 / p>

页面看起来像这样:

<base:mypagebase...>
    <ContentPage.Resources>
       ...
    </ContentPage.Resources>
    <ContentPage.Content>
       <RelativeLayout x:Name="ViewContentLayout" VerticalOptions="FillAndExpand">
          ....
       </RelativeLayou>
    </ContentPage.Content>
</base:mypagebase>

mpage.xaml.cs之后,我正在尝试在InitializeComponent()的构造函数中将RelativeLayout包装在ScrollView

类似这样的东西:

if (Device.RuntimePlatform == Device.iOS)
{
    var scroll = new ScrollView();
    scroll.Orientation = ScrollOrientation.Vertical;
    scroll.VerticalOptions = LayoutOptions.FillAndExpand;
    scroll.Content = ViewContentLayout;
    Content = scroll;
}

它通过但稍后会引发异常:

Object reference not set to an instance of an object

at Xamarin.Forms.RelativeLayout.OnSizeRequest (System.Double widthConstraint, System.Double heightConstraint) [0x00017] in RelativeLayout.cs:185

1 个答案:

答案 0 :(得分:0)

属性的调用顺序很重要,似乎必须先设置内容根:

updated() {
  this.images = images;
  console.log(this.$refs);
  console.log(this.$refs.im);
}