【发布时间】:2015-06-11 14:08:16
【问题描述】:
我希望此示例代码创建 3 个嵌套框,每个框都位于其父级的中心。我的理解基于What is the difference between Xamarin.Form's LayoutOptions, especially Fill and Expand?。这些框似乎水平居中,但不是垂直居中。
完整回购:https://github.com/pawelpabich/Xamarin-Forms-Nested-Content
示例代码:
var mainPage = new ContentPage();
var content = new StackLayout()
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
BackgroundColor = Color.Yellow,
HeightRequest = 200,
WidthRequest = 200,
Children =
{
new StackLayout()
{
BackgroundColor = Color.Blue,
HeightRequest = 100,
WidthRequest = 100,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Children =
{
new StackLayout()
{
BackgroundColor = Color.Green,
HeightRequest = 50,
WidthRequest = 50,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
}
}
}
}
};
mainPage.Content = content;
MainPage = mainPage;
应用在 Windows 模拟器上运行时的最终结果: 。
【问题讨论】:
标签: xamarin.forms