我在我的xaml页面中使用框架,我使用以下示例
<StackLayout>
<Frame>
<StackLayout>
<Button></Button>
<Label></Label>
</StackLayout>
<StackLayout>
<Label></Label>
</StackLayout>
</Frame>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
但是当我想在cs方面做同样的事情时,我定义了StackLayouts,我定义了标签和按钮.我可以使用Children向Stacklayout添加Buttons但是我无法将Stacklayout添加到Frame中,因为Frame Children没有proopperties.是否有可能在cs方面之前将Stacklayout添加到Frame?
框架具有独特的属性:内容.按照以下代码段在后面的代码中创建您的UI:
var stackLayout = new StackLayout();
//add content...
stackLayout.Children.Add(new Label);
var frame = new Frame;
frame.Content = stackLayout
此外,如果您想在Frame中有多个子项,请将其包装在一个唯一的Container(Grid,RelativeLayout,AbsoluteLayout,...)中
请参阅https://developer.xamarin.com/api/type/Xamarin.Forms.Frame/