我是Xamarin Forms的新手,我正在尝试创建一个视图并将按钮添加为视图的子视图。我无法将孩子添加到"查看"类。如何将子视图/子项添加到"查看"以编码方式编写的xamarin课程?
答案 0 :(得分:0)
您必须使用布局(https://developer.xamarin.com/guides/xamarin-forms/controls/layouts/)
最简单的方法是使用StackLayout
:https://developer.xamarin.com/api/type/Xamarin.Forms.StackLayout/
StackLayout stackLayout = new StackLayout
{
Spacing = 0,
VerticalOptions = LayoutOptions.FillAndExpand,
Children =
{
new Button
{
Text = "Button 1",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
},
new Button
{
Text = "Button 2",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
},
new Button
{
Text = "Button 3",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.CenterAndExpand
}
}
}