StackLayout中的StackLayout创建溢出

时间:2018-12-18 20:44:21

标签: c# xaml xamarin xamarin.forms

我正在创建一个菜单,这是场景:

enter image description here

(我只是隐藏商品名称)

这是代码:

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);
            }
        }
    }

为什么菜单项主体溢出?我不明白,也许我错过了一些东西。

1 个答案:

答案 0 :(得分:0)

如果您检查Microsoft文档中是否有StackLayout

您会发现您的StackLayout的默认间距为6。

将“间距”设置为0应该可以解决问题。