我刚开始使用Xamarin进行试用,我正在尝试研究它是如何工作的。
我想创建一个包含三行的简单页面,其中包含以下要求:
我试图直接使用代码执行此页面来创建此页面:
public SamplePage() {
this.Padding = new Thickness( 10, Device.OnPlatform( 20, 0, 0 ), 10, 0 );
var homeLogo = new Image() {
Aspect = Aspect.AspectFit
};
homeLogo.Source = ImageSource.FromFile( "HomeLogo.png" );
var btn1 = new Button() {
Text = "first button"
};
var btn2 = new Button() {
Text = "second button"
};
this.Content = new StackLayout {
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Orientation = StackOrientation.Vertical,
Children = {
homeLogo,
new Label {
VerticalOptions = LayoutOptions.FillAndExpand,
Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in dolor maximus, molestie elit quis, condimentum ipsum."
},
btn1,
btn2
}
};
}
我在Visual Studio中使用Xamarin并使用Portabe类库创建了一个Xamarin Forms项目。是否有任何设计师可以用来开始学习如何创建UI?
答案 0 :(得分:1)
尝试以下方法。我认为你错过了这样一个事实:内部容器有能力扩展父容器应该具有相同的属性设置来扩展。
this.Content = new StackLayout {
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.Center,
Orientation = StackOrientation.Vertical,
Children = {
homeLogo,
new Label {
VerticalOptions = LayoutOptions.CenterAndExpand,
Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas in dolor maximus, molestie elit quis, condimentum ipsum."
},
btn1,
btn2
}
};