我使用 <Frame>
在我的 xaml
像这样的页面:
<StackLayout>
<Frame>
<StackLayout>
<Button></Button>
<Label></Label>
</StackLayout>
<StackLayout>
<Label></Label>
</StackLayout>
</Frame>
</StackLayout>
但我想在 C# 端做同样的事情。
我定义了 StackLayout
, Label
和 Button
.
现在我可以添加 Button
到 StackLayout
使用 Children
, 但我无法添加 StackLayout
到 Frame
因为它没有 Children
属性(property)。
是否可以添加 StackLayout
在 Frame
里面使用 C# 作为后台代码?
最佳答案
框架有一个独特的属性:内容。按照此代码段在代码隐藏中创建您的 UI:
var stackLayout = new StackLayout();
//add content...
stackLayout.Children.Add(new Label);
var frame = new Frame;
frame.Content = stackLayout
此外,如果你想在你的框架中有多个 child ,将它包装在一个独特的容器中(Grid、RelativeLayout、AbsoluteLayout,...)
参见 https://developer.xamarin.com/api/type/Xamarin.Forms.Frame/
关于c# - 使用 C# 作为后台代码在 Xamarin Forms 的框架内创建 StackLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46783966/