我正在创建一个菜单,这是场景:
(我只是隐藏商品名称)
这是代码:
public Menu(List<Document> documents, MenuItem parent) {
ParentItem = parent;
Orientation = StackOrientation.Vertical;
HorizontalOptions = LayoutOptions.FillAndExpand;
VerticalOptions = LayoutOptions.FillAndExpand;
Spacing = 0;
Margin = new Thickness(0);
Padding = new Thickness(0);
if (documents.Count > 0)
foreach (Document doc in documents)
AddItem(new MenuItem(doc, this));
}
public MenuItem(Document doc, Menu parent) {
Orientation = StackOrientation.Vertical;
HorizontalOptions = LayoutOptions.FillAndExpand;
VerticalOptions = LayoutOptions.Start;
BackgroundColor = Color.Transparent;
Spacing = 0;
Margin = new Thickness(0);
Padding = new Thickness(0);
Document = doc;
Parent = parent;
Head = new MenuItemHead(doc);
var bdy = new StackLayout() {
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Color.Transparent,
Spacing = 0,
Margin = new Thickness(0),
Padding = new Thickness(15, 0, 0, 0)
};
bdy.Children.Add(new Menu(doc.Documents, this));
Body = bdy;
Active = false;
if (!doc.IsFolderOpen) {
var tapped = new TapGestureRecognizer();
tapped.Tapped += (s, e) => {
bool wasActive = Active;
parent.CollapseItems();
if (!wasActive) Show();
};
Head.GestureRecognizers.Add(tapped);
} else {
if (doc.Documents.Count > 0) {
var tapped = new TapGestureRecognizer();
tapped.Tapped += async (s, e) => {
await MenuView.Push(new Menu(doc.Documents, this));
};
Head.GestureRecognizers.Add(tapped);
}
}
}
为什么菜单项主体溢出?我不明白,也许我错过了一些东西。