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