1

我是Xamarin和移动开发人员的新手,并且无法将堆栈布局加载到活动中。所以我有这个布局中的一类:如何将StackLayout添加到活动

public class TestStackLayout : ContentPage 
{ 
    public TestStackLayout() 
    { 
     StackLayout stackLayout = new StackLayout 
     { 
      Spacing = 0, 
      VerticalOptions = LayoutOptions.FillAndExpand, 
      Children = 
      { 
       new Label 
       { 
        Text = "StackLayout" 
       } 
      } 
     }; 
    } 
} 

而这个活动,这就是所谓在MainActivity一个按钮:

[Activity (Label = "TestActivity")] 
public class TestActivity : Activity 
{ 
    protected override void OnCreate (Bundle bundle) 
    { 
     base.OnCreate (bundle); 
    } 
} 

我的问题是:如何将我的TestStackLayout添加到测试活动?

回答

3

您的TestStackLayout定义为ContentPage而不是布局本身。因此,它会在您的应用上呈现一个页面(在每个平台上)。

当你使用Xamarin.Forms(这就是关键)时,你不需要为每个页面添加一个活动。你只需要一个加载Xamarin.Forms和应用程序的MainActivity。其余由Xamarin.Forms完成。

请看Xamarin的this sample。你可以直接dive into the code了解最新情况。

要开始Xamarin.Forms读取this introduction guide