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

标签 c# xamarin xamarin.forms code-behind children

我使用 <Frame>在我的 xaml像这样的页面:

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

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

我定义了 StackLayout , LabelButton .

现在我可以添加 ButtonStackLayout使用 Children , 但我无法添加 StackLayoutFrame因为它没有 Children属性(property)。

是否可以添加 StackLayoutFrame 里面使用 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/

相关文章:

c# - 递归类 C#

C#-异步执行中的四种模式

c# - 如何从 Url 下载图像并将其保存到本地 SQLite 数据库

c# - Xamarin iOS 调试需要永远,不加载模拟器

android - Xamarin 资源目录 ..\.\res 不存在

c# - ASP.NET 身份(使用 IdentityServer4)获取外部资源 oauth 访问 token

c# - Accord.NET 中的多标签支持向量机

android - 自 XS 6 以来不再调用 Xamarin.Android 应用程序

azure - 访问/.auth/refresh权限错误

android - 在Windows 10和VS2015 Android模拟器上运行时,Android App崩溃