代码之家  ›  专栏  ›  技术社区  ›  KalleP

在一个帧中添加两个StackLayout-代码隐藏(而不是xaml)

  •  0
  • KalleP  · 技术社区  · 6 年前

    我有一个水平的stacklayout,但我需要添加一个按钮,该按钮应该位于框架中其他项目的上方。

    我尝试添加另一个stacklayout,但它抱怨。

    var stackLayout = new StackLayout
                    {
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions = LayoutOptions.Center,
                        Orientation = StackOrientation.Horizontal,
                        Children = {image, label}
                    };
    
                    var buttonStackLayout = new StackLayout
                    {
                        Children = {addButton}
                    };
    
                    return new ViewCell { View = stackLayout};
    

    当我尝试这样做时:

    return new ViewCell { View = stackLayout && buttonStackLayout};
    

    它说我不能有2个堆栈布局的操作数。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Miguel Angel Muñoz    6 年前

    视图=堆栈布局&&按钮堆栈布局错误。

    你需要使用:

    View = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    Children = {stackLayout , buttonStackLayout}
                };