繁体   English   中英

使用 C# 作为后台代码在 Xamarin Forms 中的框架内创建 StackLayout

[英]Create a StackLayout inside a Frame in Xamarin Forms using C# as background code

我在我的xaml页面中使用了一个<Frame> ,如下所示:

<StackLayout>
    <Frame>
        <StackLayout>
            <Button></Button>
            <Label></Label>
        </StackLayout>
        <StackLayout>
            <Label></Label>
        </StackLayout>
    </Frame>
</StackLayout>

但我想在 C# 方面做同样的事情。

我定义了StackLayoutLabelButton

现在我可以使用ChildrenButton添加到StackLayout ,但我无法将StackLayout添加到Frame因为它没有Children属性。

是否可以使用 C# 作为后台代码在Frame添加StackLayout

一个框架有一个独特的属性:内容。 按照以下代码段在后面的代码中创建您的 UI:

var stackLayout = new StackLayout(); //add content... stackLayout.Children.Add(new Label); var frame = new Frame; frame.Content = stackLayout

此外,如果您想在您的 Frame 中有多个孩子,请将其包装在一个唯一的容器中(Grid、RelativeLayout、AbsoluteLayout,...)

请参阅https://developer.xamarin.com/api/type/Xamarin.Forms.Frame/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM