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的错误提示,另外挂代理的话速度好一些继承