如果有可能为孩子添加多个AbsoluteLayoutFlags,我会徘徊吗?什么时候在c#中做?
我知道在XAML中有可能:
StackLayout BackgroundColor="White"
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
AbsoluteLayout.LayoutBounds="0, 0, 1, 90"
AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional">
但是当我尝试用c#做这个时,我显然只能添加一个:
layout.Children.Add(topMenu(), new Rectangle(0, 0, 1, 90), AbsoluteLayoutFlags.PositionProportional);
希望得到这方面的帮助,并提前感谢:-)
只需在Flags之间添加OR运算符即可
layout.Children.Add(topMenu, new Rectangle(0, 0, 1, 90), AbsoluteLayoutFlags.PositionProportional|AbsoluteLayoutFlags.SizeProportional|AbsoluteLayoutFlags.SizeProportional);
您可以附加|
运算符如何为AbsoluteLayoutFlags
enum
提供任何值。或者你可以尝试下面一个
您可以将AbsoluteLayoutFlags
单独添加到任何控件中。看看这个示例代码片段
var layout = new AbsoluteLayout
{
BackgroundColor = Color.Blue.WithLuminosity(0.9),
VerticalOptions = LayoutOptions.FillAndExpand
};
var topMenu = new Label
{
Text = "Left",
TextColor = Color.Black
};
AbsoluteLayout.SetLayoutFlags(topMenu,
AbsoluteLayoutFlags.None|AbsoluteLayoutFlags.PositionProportional);
AbsoluteLayout.SetLayoutBounds(topMenu,
new Rectangle(0, 0, 1, 90));
layout.Children.Add(topMenu);