[Xamarin] Hello world

App entrance:c#

namespace first_portable_demo
{
    public class App
    {
        public static Page GetMainPage()
        {
            return new GreetingsPage();
        }
    }
}

Test page :網站

namespace first_portable_demo
{
    class GreetingsPage : ContentPage
    {
        public GreetingsPage()
        {
            this.Content = new Label
            {
                Text = "Greetings, Xamarin"
            };

            //適配不一樣的平臺
            this.Padding = new Thickness(0, Device.OnPlatform(20,0,0),0,0);            
        }
    }
}

ContentPage基類Page參考:this

    // Summary:
    //     A Xamarin.Forms.VisualElement that occupies most or all of the screen and
    //     contains a single child.
    //
    // Remarks:
    //     To be added.
    public class Page : VisualElement, ILayout
    {        
        //
        // Summary:
        //     The space between the content of the Xamarin.Forms.Page and it's border.
        //
        // Remarks:
        //     To be added.
        public Thickness Padding { get; set; }

其餘UI Control位置調整方式: 對label的屬性賦值 (Label繼承與View)
spa

public GreetingsPage()
{
     this.Content = new Label
     {
           Text = "Greetings, Xamarin",
           HorizontalOptions = LayoutOptions.Center,
           VerticalOptions = LayoutOptions.Center
      };          
 }

使用Label自身屬性特性:代理

this.Content = new Label
{
      Text = "Greetings, Xamarin",                
      XAlign = TextAlignment.Center,
      YAlign = TextAlignment.Center
};

更多Label屬性參看Xamarin API,相應的屬性也會提供內部設定好的類型/枚舉,好比Font類code

也能夠操做Label的FormattedText屬性 orm

明天過一下基本的layout特性,Xamarin網站是否是自己就不穩定,常常看到IIS的錯誤提示,另外掛代理的話速度好一些繼承

相關文章
相關標籤/搜索