App entrance:
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参考:
// 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)
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类
也可以操作Label的FormattedText属性
明天过一下基本的layout特性,Xamarin网站是不是本身就不稳定,经常看到IIS的错误提示,另外挂代理的话速度好一些
时间: 2024-10-14 13:50:41