I use an <Frame>
in my xaml
page like this:
<StackLayout>
<Frame>
<StackLayout>
<Button></Button>
<Label></Label>
</StackLayout>
<StackLayout>
<Label></Label>
</StackLayout>
</Frame>
</StackLayout>
But I want to do the same thing on the C# side.
I define the StackLayout
, Label
and Button
.
Now I can add the Button
to the StackLayout
using Children
, but I cannot add the StackLayout
to the Frame
because it doesn't have a Children
property.
Is it possible to add a StackLayout
inside a Frame
using C# as background code ?
A frame has a unique property: Content. Follow this snippet to create your UI in code behind:
var stackLayout = new StackLayout();
//add content...
stackLayout.Children.Add(new Label);
var frame = new Frame;
frame.Content = stackLayout
Moreover, if you want to have multiple children in your Frame, wrap it in an unique Container (Grid, RelativeLayout, AbsoluteLayout, ...)
See https://developer.xamarin.com/api/type/Xamarin.Forms.Frame/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With